levels))) { throw new \common_Exception('Level "' . $minimumLevel . '" is not managed by verbose logger'); } $this->levelPosition = array_search($minimumLevel, $this->levels); } /** * Log message following minimum level of verbosity * If $level is bigger than minimum verbosity required * Set color associated to $level * * @param mixed $level * @param string $message * @param array $context */ public function log($level, $message, array $context = []) { $this->logMessage( $level, $this->getFormattedMessage($level, $message) ); } /** * Log message following minimum level of verbosity * If $level is bigger than minimum verbosity required * * @param mixed $level * @param string $message */ protected function logMessage($level, $message) { if (array_search($level, $this->levels) > $this->levelPosition) { return; } echo $message; } /** * Returns the formatted message. * * @param $level * @param $message * * @return string */ public function getFormattedMessage($level, $message) { return '[' . (new \DateTime())->format('Y-m-d H:i') . ']' . str_pad('[' . $level . ']', 12) . $message . PHP_EOL; } }