mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-23 17:46:09 +02:00
Merge branch '1.x'
This commit is contained in:
@@ -106,7 +106,7 @@ class GelfMessageFormatter extends NormalizerFormatter
|
||||
}
|
||||
|
||||
foreach ($record['extra'] as $key => $val) {
|
||||
$val = is_scalar($val) ? $val : $this->toJson($val);
|
||||
$val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
|
||||
$len += strlen($this->extraPrefix . $key . $val);
|
||||
if ($len > self::MAX_LENGTH) {
|
||||
$message->setAdditional($this->extraPrefix . $key, substr($val, 0, self::MAX_LENGTH - $len));
|
||||
@@ -116,7 +116,7 @@ class GelfMessageFormatter extends NormalizerFormatter
|
||||
}
|
||||
|
||||
foreach ($record['context'] as $key => $val) {
|
||||
$val = is_scalar($val) ? $val : $this->toJson($val);
|
||||
$val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
|
||||
$len += strlen($this->contextPrefix . $key . $val);
|
||||
if ($len > self::MAX_LENGTH) {
|
||||
$message->setAdditional($this->contextPrefix . $key, substr($val, 0, self::MAX_LENGTH - $len));
|
||||
|
@@ -186,6 +186,9 @@ class JsonFormatter extends NormalizerFormatter
|
||||
foreach ($trace as $frame) {
|
||||
if (isset($frame['file'])) {
|
||||
$data['trace'][] = $frame['file'].':'.$frame['line'];
|
||||
} elseif (isset($frame['function']) && $frame['function'] === '{closure}') {
|
||||
// We should again normalize the frames, because it might contain invalid items
|
||||
$data['trace'][] = $frame['function'];
|
||||
} else {
|
||||
// We should again normalize the frames, because it might contain invalid items
|
||||
$data['trace'][] = $this->normalize($frame);
|
||||
|
@@ -129,6 +129,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
foreach ($trace as $frame) {
|
||||
if (isset($frame['file'])) {
|
||||
$data['trace'][] = $frame['file'].':'.$frame['line'];
|
||||
} elseif (isset($frame['function']) && $frame['function'] === '{closure}') {
|
||||
// We should again normalize the frames, because it might contain invalid items
|
||||
$data['trace'][] = $frame['function'];
|
||||
} else {
|
||||
// We should again normalize the frames, because it might contain invalid items
|
||||
$data['trace'][] = $this->toJson($this->normalize($frame), true);
|
||||
|
@@ -81,6 +81,26 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually activate this logger regardless of the activation strategy
|
||||
*/
|
||||
public function activate()
|
||||
{
|
||||
if ($this->stopBuffering) {
|
||||
$this->buffering = false;
|
||||
}
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
$record = end($this->buffer) ?: null;
|
||||
|
||||
$this->handler = call_user_func($this->handler, $record, $this);
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
throw new \RuntimeException("The factory callable should return a HandlerInterface");
|
||||
}
|
||||
}
|
||||
$this->handler->handleBatch($this->buffer);
|
||||
$this->buffer = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -96,17 +116,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
|
||||
array_shift($this->buffer);
|
||||
}
|
||||
if ($this->activationStrategy->isHandlerActivated($record)) {
|
||||
if ($this->stopBuffering) {
|
||||
$this->buffering = false;
|
||||
}
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
$this->handler = call_user_func($this->handler, $record, $this);
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
throw new \RuntimeException("The factory callable should return a HandlerInterface");
|
||||
}
|
||||
}
|
||||
$this->handler->handleBatch($this->buffer);
|
||||
$this->buffer = array();
|
||||
$this->activate();
|
||||
}
|
||||
} else {
|
||||
$this->handler->handle($record);
|
||||
|
@@ -92,23 +92,27 @@ class NewRelicHandler extends AbstractProcessingHandler
|
||||
newrelic_notice_error($record['message']);
|
||||
}
|
||||
|
||||
foreach ($record['formatted']['context'] as $key => $parameter) {
|
||||
if (is_array($parameter) && $this->explodeArrays) {
|
||||
foreach ($parameter as $paramKey => $paramValue) {
|
||||
$this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue);
|
||||
if (isset($record['formatted']['context'])) {
|
||||
foreach ($record['formatted']['context'] as $key => $parameter) {
|
||||
if (is_array($parameter) && $this->explodeArrays) {
|
||||
foreach ($parameter as $paramKey => $paramValue) {
|
||||
$this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue);
|
||||
}
|
||||
} else {
|
||||
$this->setNewRelicParameter('context_' . $key, $parameter);
|
||||
}
|
||||
} else {
|
||||
$this->setNewRelicParameter('context_' . $key, $parameter);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($record['formatted']['extra'] as $key => $parameter) {
|
||||
if (is_array($parameter) && $this->explodeArrays) {
|
||||
foreach ($parameter as $paramKey => $paramValue) {
|
||||
$this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue);
|
||||
if (isset($record['formatted']['extra'])) {
|
||||
foreach ($record['formatted']['extra'] as $key => $parameter) {
|
||||
if (is_array($parameter) && $this->explodeArrays) {
|
||||
foreach ($parameter as $paramKey => $paramValue) {
|
||||
$this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue);
|
||||
}
|
||||
} else {
|
||||
$this->setNewRelicParameter('extra_' . $key, $parameter);
|
||||
}
|
||||
} else {
|
||||
$this->setNewRelicParameter('extra_' . $key, $parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,10 @@ use Monolog\Logger;
|
||||
*/
|
||||
class RotatingFileHandler extends StreamHandler
|
||||
{
|
||||
const FILE_PER_DAY = 'Y-m-d';
|
||||
const FILE_PER_MONTH = 'Y-m';
|
||||
const FILE_PER_YEAR = 'Y';
|
||||
|
||||
protected $filename;
|
||||
protected $maxFiles;
|
||||
protected $mustRotate;
|
||||
@@ -64,6 +68,20 @@ class RotatingFileHandler extends StreamHandler
|
||||
|
||||
public function setFilenameFormat($filenameFormat, $dateFormat)
|
||||
{
|
||||
if (!in_array($dateFormat, array(self::FILE_PER_DAY, self::FILE_PER_MONTH, self::FILE_PER_YEAR))) {
|
||||
trigger_error(
|
||||
'Invalid date format - format should be one of '.
|
||||
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
|
||||
'or RotatingFileHandler::FILE_PER_YEAR.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
if (substr_count($filenameFormat, '{date}') === 0) {
|
||||
trigger_error(
|
||||
'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
$this->filenameFormat = $filenameFormat;
|
||||
$this->dateFormat = $dateFormat;
|
||||
$this->url = $this->getTimedFilename();
|
||||
|
@@ -35,6 +35,8 @@ class WhatFailureGroupHandler extends GroupHandler
|
||||
$handler->handle($record);
|
||||
} catch (\Exception $e) {
|
||||
// What failure?
|
||||
} catch (\Throwable $e) {
|
||||
// What failure?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +53,8 @@ class WhatFailureGroupHandler extends GroupHandler
|
||||
$handler->handleBatch($records);
|
||||
} catch (\Exception $e) {
|
||||
// What failure?
|
||||
} catch (\Throwable $e) {
|
||||
// What failure?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user