本文整理汇总了PHP中Monolog\Logger::addRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP Logger::addRecord方法的具体用法?PHP Logger::addRecord怎么用?PHP Logger::addRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monolog\Logger
的用法示例。
在下文中一共展示了Logger::addRecord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doLog
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: 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: write
/**
* 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: log
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: log
/**
* @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: addRecord
/**
* 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: handleError
/**
* 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: log
/**
* {@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: log
/**
* {@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: addRecord
/**
* @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: export
/**
* 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: addRecord
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: testHandleWithException
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: log
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: write
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());
}