addRecord() public method

Adds a log record.
public addRecord ( integer $level, string $message, array $context = [] ) : boolean
$level integer The logging level
$message string The log message
$context array The log context
return boolean Whether the record has been processed
コード例 #1
0
 public static function doLog($logmethod, array $data, &$output)
 {
     $log = new Logger('ezperflogger');
     // constructor args for the specific handler can be set via ini
     /// @todo how to create resources instead?
     foreach (eZPerfLoggerINI::variable('MonologSettings', 'LogHandlers') as $handlerName) {
         $handlerClass = 'Monolog\\Handler\\' . $handlerName . "Handler";
         if (eZPerfLoggerINI::hasVariable('MonologSettings', 'LogHandler_' . $handlerName)) {
             $r = new ReflectionClass($handlerClass);
             $handler = $r->newInstanceArgs(eZPerfLoggerINI::variable('MonologSettings', 'LogHandler_' . $handlerName));
         } else {
             $handler = new $handlerClass();
         }
         $log->pushHandler($handler);
     }
     // the default severity level: taken from config file
     $level = (int) eZPerfLoggerINI::variable('MonologSettings', 'SeverityLevel');
     // either coalesce messages or not: taken from config file
     if (eZPerfLoggerINI::variable('MonologSettings', 'Coalescevariables') == 'enabled') {
         /// @todo allow via ini file the specification of custom formatters?
         $msg = array();
         foreach ($data as $varname => $value) {
             $msg[] = "{$varname}: {$value}";
         }
         $log->addRecord($level, implode(', ', $msg));
     } else {
         foreach ($data as $varname => $value) {
             $log->addRecord($level, "{$varname}: {$value}");
         }
     }
 }
コード例 #2
0
ファイル: MonologLogAdapter.php プロジェクト: phpi/log
 /**
  * {@inheritdoc}
  */
 public function log($message, $priority = LOG_INFO)
 {
     if (!isset(self::$mapping[$priority])) {
         throw new \InvalidArgumentException('Invalid priority ' . $priority);
     }
     $this->logger->addRecord(self::$mapping[$priority], $message);
 }
コード例 #3
0
ファイル: LogWriter.php プロジェクト: krisanalfa/b-comp
 /**
  * Write to log
  *
  * @param string $message
  * @param int    $level
  * @param array  $context
  *
  * @return void
  */
 public function write($level, $message, array $context = array())
 {
     if (!$this->resource) {
         // create a log channel
         $this->makeResource();
     }
     // Don't bother typesetting $message, Monolog will do this for us
     $this->resource->addRecord($this->getLogLevel($level, Logger::WARNING), $message, $context);
 }
コード例 #4
0
 public function log($message, $priority = self::INFO)
 {
     $context = ['at' => Helpers::getSource()];
     if ($message instanceof Throwable) {
         $context['exception'] = $message;
         $message = '';
     }
     $this->monolog->addRecord(self::PRIORITY_MAP[$priority] ?? Monolog\Logger::ERROR, $message, $context);
 }
コード例 #5
0
 /**
  * @param string $message
  * @param int $priority Priority is ignored, since its value is extracted from the response
  * @param null $extras
  */
 public function log($message, $priority = LOG_INFO, $extras = null)
 {
     /** @var Response $response */
     $response = $extras['response'];
     $priority = $this->getPriorityFromResponse($response);
     $context = $this->getContextFromResponse($response);
     $context['event'] = 'request.complete';
     $this->log->addRecord($priority, $message, $context);
     if ($response->isError()) {
         /** @var Request $request */
         $request = $extras['request'];
         $context['event'] = 'request.error';
         $this->log->addRecord($response->isClientError() ? Logger::WARNING : Logger::ERROR, sprintf('Request failed with code %s: %s %s', $response->getStatusCode(), $request->getMethod(), $request->getUrl()), $context);
     }
 }
コード例 #6
0
ファイル: MutedLogger.php プロジェクト: tmountjr/muted-log
 /**
  * Adds a log record.
  *
  * @param  integer $level   The logging level
  * @param  string  $message The log message
  * @param  array   $context The log context
  * @return Boolean Whether the record has been processed
  */
 public function addRecord($level, $message, array $context = array())
 {
     if ($message instanceof \Exception) {
         $message = MutedException::encapsulate($message);
     }
     return parent::addRecord($level, $message, $context);
 }
コード例 #7
0
 /**
  * Handle PHP error
  * Takes input from PHPs built in error handler logs it
  * throws a jazzee exception to handle if the error reporting level is high enough
  * @param $code
  * @param $message
  * @param $file
  * @param $line
  * @throws \Jazzee\Exception
  */
 public function handleError($code, $message, $file, $line)
 {
     /* Map the PHP error to a Log priority. */
     switch ($code) {
         case E_WARNING:
         case E_USER_WARNING:
             $priority = \Monolog\Logger::WARNING;
             break;
         case E_NOTICE:
         case E_USER_NOTICE:
             $priority = \Monolog\Logger::INFO;
             break;
         case E_ERROR:
         case E_USER_ERROR:
             $priority = \Monolog\Logger::ERROR;
             break;
         default:
             $priority = \Monolog\Logger::INFO;
     }
     // Error reporting is currently turned off or suppressed with @
     if (error_reporting() === 0) {
         $this->_log->debug('Supressed error: ' . $message . ' in ' . $file . ' at line ' . $line);
         return false;
     }
     $this->_log->addRecord($priority, $message . ' in ' . $file . ' at line ' . $line);
     throw new \Exception('Jazzee caught a PHP error: ' . $message . ' in ' . $file . ' at line ' . $line);
 }
コード例 #8
0
ファイル: Log.php プロジェクト: kisma/kisma
 /**
  * {@InheritDoc}
  */
 public static function log($message, $level = Logger::INFO, $context = array())
 {
     static $_firstRun = true;
     if ($_firstRun || !static::$_logFileValid) {
         static::_checkLogFile();
         $_firstRun = false;
     }
     //	Get the indent, if any
     $_unindent = ($_newIndent = static::_processMessage($message)) > 0;
     //	Indent...
     if (0 > ($_tempIndent = static::$_currentIndent - ($_unindent ? 1 : 0))) {
         $_tempIndent = 0;
     }
     $_message = str_repeat('  ', $_tempIndent) . $message;
     if (!is_numeric($level)) {
         $level = LoggingLevels::toNumeric($level);
     }
     if (static::$_logger) {
         static::$_logger->addRecord($level, $_message, !is_array($context) ? array() : $context);
     } elseif (static::$_fallbackLogger) {
         static::$_fallbackLogger->addRecord($level, $_message, $context);
     }
     //	Set indent level...
     static::$_currentIndent += $_newIndent;
     //	Anything over a warning returns false so you can chain
     return Logger::WARNING > $level;
 }
コード例 #9
0
 /**
  * {@inheritDoc}
  */
 public function log($level, $message, array $context = [])
 {
     if (!$this->options['logging_enabled']) {
         return false;
     }
     // Add the queue name and provider to the context
     $context = array_merge(['queue' => $this->name, 'provider' => $this->getProvider()], $context);
     return $this->logger->addRecord($level, $message, $context);
 }
コード例 #10
0
ファイル: CLogger.php プロジェクト: iwatea/Swim
 /**
  * @see Monolog\Logger::addRecord()
  */
 public function addRecord($level, $message, array $context = array())
 {
     // 配列のメッセージに対応させる
     if (!is_array($message)) {
         $message = array($message);
     }
     foreach ($message as $_message) {
         parent::addRecord($level, $_message, $context);
     }
 }
コード例 #11
0
 /**
  * Writes log messages to a LogEntriesHandler Monolog handler.
  */
 public function export()
 {
     $monolog = new Logger('Logentries');
     $monolog->pushHandler(new LogEntriesHandler($this->logToken));
     foreach ($this->messages as $message) {
         if (array_key_exists($message[1], $this->_monologLevels)) {
             $monolog->addRecord($this->_monologLevels[$message[1]], $this->formatMessage($message), isset($message[4]) && is_array($message[4]) ? $message[4] : []);
         }
     }
 }
コード例 #12
0
 public function addRecord($level, $message, array $context = array())
 {
     if ($message instanceof \Exception) {
         $context['title'] = $message->getMessage();
         $handler = new ExceptionHandler($this);
         $message = $handler->renderExceptionForLogger($message);
     } else {
         $context['title'] = $message;
     }
     return parent::addRecord($level, $message, $context);
 }
コード例 #13
0
ファイル: SystemHandlerTest.php プロジェクト: aaleksu/bolt_cm
 public function testHandleWithException()
 {
     $app = $this->getApp();
     $app['request'] = Request::createFromGlobals("/");
     $log = new Logger('logger.system');
     $log->pushHandler(new SystemHandler($app));
     $mocker = new DoctrineMockBuilder();
     $db = $mocker->getConnectionMock();
     $db->expects($this->any())->method('insert')->with($this->equalTo("bolt_log_system"));
     $app['db'] = $db;
     $log->addRecord(Logger::DEBUG, 'test', array('event' => '', 'exception' => new \Exception()));
 }
コード例 #14
0
 public function log($message, $priority = self::INFO)
 {
     if (!is_array($message) && method_exists($this, 'logException')) {
         // forward BC with Nette in 2.3-dev
         $exceptionFile = $message instanceof \Exception ? $this->logException($message) : NULL;
         $message = array(@date('[Y-m-d H-i-s]'), $this->formatMessage($message), ' @ ' . self::getSource(), $exceptionFile ? ' @@ ' . basename($exceptionFile) : NULL);
         if (in_array($priority, array(self::ERROR, self::EXCEPTION, self::CRITICAL), TRUE)) {
             $this->sendEmail(implode('', $message));
         }
     }
     $normalised = $message;
     $context = array('at' => self::getSource());
     if (is_array($message)) {
         // bc with Nette until 2.3
         if (count($message) >= 2 && preg_match('~\\[[\\d+ -]+\\]~i', $message[0])) {
             array_shift($message);
             // first entry is probably time
         }
         if (isset($message[1]) && preg_match('~\\@\\s+https?:\\/\\/.+~', $message[1]) || preg_match('~CLI:.+~i', $message[1])) {
             $context['at'] = ltrim($message[1], '@ ');
             unset($message[1]);
         }
         if (isset($message[2]) && preg_match('~\\@\\@\\s+exception\\-[^\\s]+\\.html~', $message[2])) {
             $context['tracy'] = ltrim($message[2], '@ ');
             unset($message[2]);
         }
         $normalised = implode($message);
     }
     $levels = $this->monolog->getLevels();
     $level = isset($levels[$uPriority = strtoupper($priority)]) ? $levels[$uPriority] : Monolog\Logger::INFO;
     switch ($priority) {
         case 'access':
             $this->monolog->addInfo($normalised, array('priority' => $priority) + $context);
             break;
         default:
             $this->monolog->addRecord($level, $normalised, array('priority' => $priority) + $context);
     }
     return isset($context['tracy']) ? $context['tracy'] : '';
 }
コード例 #15
0
ファイル: PapertrailHandler.php プロジェクト: nztim/logger
 public function write(Entry $entry)
 {
     if (!$this->isTriggered($entry)) {
         return;
     }
     $output = "%channel%.%level_name%: %message%";
     $formatter = new LineFormatter($output);
     $name = env('LOGGER_APP_NAME') . '-' . $entry->getChannel();
     $log = new MonologLogger($name);
     $syslogHandler = new SyslogUdpHandler(env('LOGGER_PAPERTRAIL_HOST'), env('LOGGER_PAPERTRAIL_PORT'));
     $syslogHandler->setFormatter($formatter);
     $log->pushHandler($syslogHandler);
     $log->addRecord($entry->getCode(), $entry->getMessage(), $entry->getContext());
 }
コード例 #16
0
 public function testHandle()
 {
     $app = $this->getApp();
     $app['config']->set('general/changelog/enabled', true);
     $log = new Logger('logger.system');
     $handler = new RecordChangeHandler($app);
     $mocker = new DoctrineMockBuilder();
     $db = $mocker->getConnectionMock();
     $db->expects($this->once())->method('insert')->with($this->equalTo('bolt_log_change'), $this->callback(function ($arg) {
         return isset($arg['diff']) && $arg['diff'] === '{"title":["test","test2"]}';
     }));
     $app['db'] = $db;
     $log->pushHandler($handler);
     $log->addRecord(Logger::DEBUG, 'test', ['action' => 'UPDATE', 'contenttype' => 'pages', 'id' => 1, 'old' => ['title' => 'test'], 'new' => ['title' => 'test2'], 'comment' => 'An Update']);
 }
コード例 #17
0
ファイル: Logger.php プロジェクト: phpguard/phpguard
 /**
  * Adds a log record
  * @param int    $level
  * @param string $message
  * @param array  $context
  *
  * @return bool
  */
 public function addRecord($level, $message, array $context = array())
 {
     $replacement = array();
     foreach ($context as $key => $value) {
         if (!is_array($value)) {
             $rkey = '%' . $key . '%';
             $replacement[$rkey] = $value;
             if (false !== strpos($message, $rkey)) {
                 unset($context[$key]);
             }
         }
     }
     $message = strtr($message, $replacement);
     return parent::addRecord($level, $message, $context);
 }
コード例 #18
0
 /**
  * Logs an operation
  * 
  * @param string $operation
  * @param string|array $id
  * @param int $ttl
  * @param bool $hit
  */
 protected function log($operation, $id = null, $ttl = null, $hit = null)
 {
     $message = strtoupper($operation);
     if ($id !== null) {
         $id = implode(', ', (array) $id);
         if ($ttl !== null) {
             $message = sprintf('%s(%s, ttl=%s)', $message, $id, $ttl);
         } else {
             $message = sprintf('%s(%s)', $message, $id);
         }
     }
     if ($hit !== null) {
         $message .= ' = ' . ($hit ? 'HIT' : 'MISS');
     }
     $this->logger->addRecord($this->logLevel, $message);
 }
コード例 #19
0
ファイル: ACL.php プロジェクト: Rudi9719/stein-syn
 /**
  * Search ACEs associated with specified role, resource and permission.
  *
  * This method returns true or false only if specified role has directly granted or revoked specified permission to specified
  * resource. Otherwise it returns null.
  *
  * @param string $roleId
  * @param string $resourceId
  * @param string $permissionId
  * @param array $params
  * @return bool|null
  */
 protected function searchACEs($roleId, $resourceId, $permissionId, array $params = array(), $level = 0)
 {
     if (!isset($this->ACEs[$roleId][$resourceId][$permissionId])) {
         return null;
     } else {
         $allowedAny = null;
         foreach ($this->ACEs[$roleId][$resourceId][$permissionId] as $ace) {
             $allowed = $ace->isAllowed($params);
             if (isset($this->logger)) {
                 $this->logger->addRecord(Logger::INFO, sprintf(" %s%s ACE (class: %s) {resource: %s (class: %s), role: %s (class: %s), permission: %s (class: %s)}", str_repeat('  ', $level), isset($allowed) ? $allowed ? 'Access granted by' : 'Access denied by' : 'No decision from', $ace, $ace->getResource(), get_class($ace->getResource()), $ace->getRole(), get_class($ace->getRole()), $this->permissions[$permissionId], get_class($this->permissions[$permissionId])));
             }
             if (isset($allowed)) {
                 if (!$allowed) {
                     return false;
                 } else {
                     $allowedAny = true;
                 }
             }
         }
         return $allowedAny;
     }
 }
コード例 #20
0
ファイル: Logger.php プロジェクト: RuntyCybin/csymfony
 /**
  * @deprecated since version 2.2, to be removed in 3.0. Use warning() which is PSR-3 compatible.
  */
 public function warn($message, array $context = array())
 {
     trigger_error('The ' . __METHOD__ . ' method inherited from the Symfony\\Component\\HttpKernel\\Log\\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the warning() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
     return parent::addRecord(BaseLogger::WARNING, $message, $context);
 }
コード例 #21
0
ファイル: Logwriter.php プロジェクト: anantab/magemonolog
 /**
  * Write a message using Monolog.
  *
  * @param  array $event  event data
  * @return void
  */
 protected function _write($event)
 {
     $level = $this->_levelMap[$event['priority']];
     $message = $event['message'];
     $this->_logger->addRecord($level, $message);
 }
コード例 #22
0
ファイル: AdyenLogger.php プロジェクト: Adyen/adyen-magento2
 /**
  * Adds a log record.
  *
  * @param  integer $level   The logging level
  * @param  string  $message The log message
  * @param  array   $context The log context
  * @return Boolean Whether the record has been processed
  */
 public function addRecord($level, $message, array $context = [])
 {
     $context['is_exception'] = $message instanceof \Exception;
     return parent::addRecord($level, $message, $context);
 }
コード例 #23
0
ファイル: MonologLogger.php プロジェクト: JerryCR/php-2
 /**
  * Logs the given message.
  *
  * @param $message Message to be logged
  */
 public function log($message)
 {
     $this->logger->addRecord($this->level, $message);
 }
コード例 #24
0
 /**
  * Adds a log record.
  *
  * @param integer $level The logging level
  * @param string $message The log message
  * @param array $context The log context
  * @return Boolean Whether the record has been processed
  * @static 
  */
 public static function addRecord($level, $message, $context = array())
 {
     return \Monolog\Logger::addRecord($level, $message, $context);
 }
コード例 #25
0
ファイル: Logger.php プロジェクト: itkg/log
 /**
  * Adds a log record.
  *
  * @param  integer $level   The logging level
  * @param  string $message The log message
  * @param  array $context The log context
  * @return Boolean Whether the record has been processed
  */
 public function addRecord($level, $message, array $context = array())
 {
     $context['id'] = $this->id;
     // Add ID in context
     return parent::addRecord($level, $message, $context);
 }
コード例 #26
0
 /**
  * Write a message to Monolog.
  *
  * @param  string $level
  * @param  string $message
  * @param  array  $context
  *
  * @return void
  */
 protected function writeLog($level, $message, $context)
 {
     $level = isset($this->levels[$level]) ? $this->levels[$level] : Logger::INFO;
     $this->logger->addRecord($level, $this->formatMessage($message), $context);
 }
コード例 #27
0
ファイル: Kengrabber.php プロジェクト: engelju/kexpgrabber
 protected function setErrorHandler(Logger $logger)
 {
     set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) use($logger) {
         $level = Logger::DEBUG;
         $message = 'PHP Warning: ';
         switch ($errno) {
             case E_STRICT:
                 $level = Logger::NOTICE;
                 $message .= 'E_STRICT';
                 break;
             case E_DEPRECATED:
                 $level = Logger::NOTICE;
                 $message .= 'E_DEPRECATED';
                 break;
             case E_USER_DEPRECATED:
                 $level = Logger::NOTICE;
                 $message .= 'E_USER_DEPRECATED';
                 break;
             case E_NOTICE:
                 $level = Logger::NOTICE;
                 $message .= 'E_NOTICE';
                 break;
             case E_WARNING:
                 $level = Logger::WARNING;
                 $message .= 'E_WARNING';
                 break;
             case E_ERROR:
                 $level = Logger::ERROR;
                 $message .= 'E_ERROR';
                 break;
             default:
                 $message .= sprintf('Unknown error level, code of %d passed', $errno);
         }
         $message .= sprintf('. Error message was "%s" in file %s at line %d.', $errstr, $errfile, $errline);
         $logger->addRecord($level, $message);
         return false;
     });
 }
コード例 #28
0
ファイル: DotLogger.php プロジェクト: jwyuen/dotslash
 public function addRecord($level, $message, array $context = array())
 {
     return parent::addRecord($level, $message, $context);
 }
コード例 #29
0
ファイル: PocLogger.php プロジェクト: flyingwhale/poc
 /**
  * Adds a log record.
  *
  * @param  integer $level   The logging level
  * @param  string  $message The log message
  * @param  array   $context The log context
  * @return Boolean Whether the record has been processed
  */
 public function addRecord($level, $message, array $context = array())
 {
     $this->selfCounter += 1;
     self::$globalCounter += 1;
     parent::addRecord($level, self::$globalCounter . ' - ' . $this->selfCounter . ' - ' . $message, $context);
 }
コード例 #30
0
ファイル: Logger.php プロジェクト: panvagenas/wp-plugin-core
 /**
  * Adds a log record.
  *
  * @param  integer $level   The logging level
  * @param  string  $message The log message
  * @param  array   $context The log context
  *
  * @return Boolean Whether the record has been processed
  */
 public function addRecord($level, $message, array $context = array())
 {
     return $this->logger->addRecord($level, $message, $context);
 }