LogLevel::DEBUG, '--verbose 4' => LogLevel::DEBUG, '-vvv' => LogLevel::INFO, '--verbose 3' => LogLevel::INFO, '-vv' => LogLevel::NOTICE, '--verbose 2' => LogLevel::NOTICE, '-v' => LogLevel::ERROR, '--verbose 1' => LogLevel::ERROR, ]; /** * Make sure it can't be instantiated. */ private function __construct() { } /** * Returns the configured instance of the verbose logger based on the arguments. * * @param array $arguments The cli arguments. * * @return ColoredVerboseLogger|VerboseLogger */ public static function getInstance(array $arguments) { if (in_array('-nc', $arguments) || in_array('--no-color', $arguments)) { return new VerboseLogger(static::getLogLevel($arguments)); } return new ColoredVerboseLogger(static::getLogLevel($arguments)); } /** * Returns the current log level based on the verbosity parameters. * * @param array $arguments * * @return string Current log level or as default LogLevel::ERROR */ protected static function getLogLevel(array $arguments) { $argumentsForSearch = implode(' ', $arguments); foreach (static::$levels as $argumentPattern => $currentLevel) { if (strpos($argumentsForSearch, $argumentPattern) !== false) { return $currentLevel; } } return LogLevel::ERROR; } }