protected function processLogs($logs)
 {
     foreach ($logs as $log) {
         // Exclude records by the exceptions handler. MonologErrorHandler takes care of them.
         if (strncmp($log[2], 'exception', 9) !== 0) {
             Monolog\Registry::main()->log(self::levelToString($log[1]), $log[0], array('message' => $log[0], 'level' => $log[1], 'category' => $log[2], 'timestamp' => $log[3] * 1000, 'environment' => Yii::app()->getComponent($this->monologComponentName)->environment));
         }
     }
 }
function getActiveLogger()
{
    if (defined('LOGGING_CHANNEL')) {
        if (!Monolog\Registry::hasLogger(LOGGING_CHANNEL)) {
            $level = defined('LOGGING_LEVEL') ? LOGGING_LEVEL : LOGGING_GLOBAL_LEVEL;
            if (is_string($level)) {
                $level = (new \ReflectionClass('Monolog\\Logger'))->getConstant($level);
            }
            Monolog\Registry::addLogger(makeLogger(LOGGING_CHANNEL, $level));
        }
        return Monolog\Registry::getInstance(LOGGING_GLOBAL_CHANNEL);
    }
    return Monolog\Registry::getInstance(LOGGING_GLOBAL_CHANNEL);
}
 public function init()
 {
     $logger = new Monolog\Logger($this->channel);
     if (!empty($this->stream_handler_filepath)) {
         $file_stream = new Monolog\Handler\StreamHandler($this->stream_handler_filepath);
         if ($this->use_json_formatter) {
             $stream->setFormatter(new Monolog\Formatter\JsonFormatter());
         }
         $logger->pushHandler($stream);
     }
     if (!empty($this->syslog_identity)) {
         $syslog = new Monolog\Handler\SyslogHandler($this->syslog_identity);
         if ($this->use_json_formatter) {
             $syslog->setFormatter(new Monolog\Formatter\JsonFormatter());
         }
         $logger->pushHandler($syslog);
     }
     Monolog\Registry::addLogger($logger, 'main');
     parent::init();
 }
Exemple #4
0
 /**
  * Helper to create named logger and add it to registry.
  * If handlers or processors not specified, they are taken from 'app' logger.
  *
  * This could be useful, say in LDAP Auth Adapter:
  *
  * $logger = Logger::createLogger('ldap');
  * $logger->error('ldap error')
  *
  * @param string $name
  * @param array $handlers
  * @param array $processors
  * @return \Monolog\Logger
  */
 public static function createLogger($name, $handlers = null, $processors = null)
 {
     if ($handlers === null) {
         $handlers = self::getInstance('app')->getHandlers();
     }
     if ($processors === null) {
         $processors = self::getInstance('app')->getProcessors();
     }
     $logger = new Monolog\Logger($name, $handlers, $processors);
     Monolog\Registry::addLogger($logger);
     return $logger;
 }
 protected function handleError($e)
 {
     Monolog\Registry::main()->addError(self::codeToString($e->code) . ': ' . $e->message, array('code' => $e->code, 'message' => $e->message, 'file' => $e->file, 'line' => $e->line, 'params' => $e->params, 'environment' => Yii::app()->getComponent($this->monologComponentName)->environment));
     parent::handleError($e);
 }