예제 #1
0
파일: Logger.php 프로젝트: michaldudek/clog
 /**
  * Logs with an arbitrary level.
  *
  * Also adds few items to the context array.
  *
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     $context = array_merge(array('_name' => $this->name, '_channel' => $this->name, '_uuid' => $this->uuid, '_tags' => isset($context['_tags']) ? is_array($context['_tags']) ? $context['_tags'] : explode(',', trim((string) $context['_tags'])) : array(), '_level' => $level, '_timestamp' => Timer::getMicroTime(), '_date' => new \DateTime()), $context);
     $message = StringUtils::interpolate((string) $message, $context);
     foreach ($this->writers as $writer) {
         $writer->log($level, $message, $context);
     }
 }
예제 #2
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     // add color to all injected variables
     $message = preg_replace_callback('/{([\\w\\d_\\.]+)}/is', function ($matches) {
         $var = $matches[1];
         return '<info>{' . $var . '}</info>';
     }, $message);
     $message = StringUtils::interpolate($message, $context);
     $alert = '';
     switch ($level) {
         case LogLevel::ALERT:
         case LogLevel::CRITICAL:
         case LogLevel::EMERGENCY:
         case LogLevel::ERROR:
             $alert = '<error> ' . $level . ' </error> ';
             break;
         case LogLevel::NOTICE:
         case LogLevel::WARNING:
             $alert = '<fg=yellow;options=bold>' . $level . '</fg=yellow;options=bold> ';
             break;
     }
     $this->output->writeln($alert . $message . '     [@mem: ' . StringUtils::bytesToString(Timer::getCurrentMemory()) . ']');
 }