mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 13:16:39 +02:00
Normalize the way backtraces are normalized and remove args for special cases, fixes #1346
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
* Added support for RFC3164 (outdated BSD syslog protocol) to SyslogUdpHandler
|
* Added support for RFC3164 (outdated BSD syslog protocol) to SyslogUdpHandler
|
||||||
* Fixed issue in GroupHandler and WhatFailureGroupHandler where setting multiple processors would duplicate records
|
* Fixed issue in GroupHandler and WhatFailureGroupHandler where setting multiple processors would duplicate records
|
||||||
* Fixed issue in SignalHandler restarting syscalls functionality
|
* Fixed issue in SignalHandler restarting syscalls functionality
|
||||||
|
* Fixed normalizers handling of exception backtraces to avoid serializing arguments in some cases
|
||||||
|
|
||||||
### 1.24.0 (2018-11-05)
|
### 1.24.0 (2018-11-05)
|
||||||
|
|
||||||
|
@@ -195,12 +195,8 @@ class JsonFormatter extends NormalizerFormatter
|
|||||||
foreach ($trace as $frame) {
|
foreach ($trace as $frame) {
|
||||||
if (isset($frame['file'])) {
|
if (isset($frame['file'])) {
|
||||||
$data['trace'][] = $frame['file'].':'.$frame['line'];
|
$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 {
|
} else {
|
||||||
// We should again normalize the frames, because it might contain invalid items
|
$data['trace'][] = (!empty($frame['class']) ? $frame['class'].$frame['type'] : '').$frame['function'];
|
||||||
$data['trace'][] = $this->normalize($frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -151,23 +151,8 @@ class NormalizerFormatter implements FormatterInterface
|
|||||||
foreach ($trace as $frame) {
|
foreach ($trace as $frame) {
|
||||||
if (isset($frame['file'])) {
|
if (isset($frame['file'])) {
|
||||||
$data['trace'][] = $frame['file'].':'.$frame['line'];
|
$data['trace'][] = $frame['file'].':'.$frame['line'];
|
||||||
} elseif (isset($frame['function']) && $frame['function'] === '{closure}') {
|
|
||||||
// Simplify closures handling
|
|
||||||
$data['trace'][] = $frame['function'];
|
|
||||||
} else {
|
} else {
|
||||||
if (isset($frame['args'])) {
|
$data['trace'][] = (!empty($frame['class']) ? $frame['class'].$frame['type'] : '').$frame['function'];
|
||||||
// Make sure that objects present as arguments are not serialized nicely but rather only
|
|
||||||
// as a class name to avoid any unexpected leak of sensitive information
|
|
||||||
$frame['args'] = array_map(function ($arg) {
|
|
||||||
if (is_object($arg) && !($arg instanceof \DateTime || $arg instanceof \DateTimeInterface)) {
|
|
||||||
return sprintf("[object] (%s)", Utils::getClass($arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $arg;
|
|
||||||
}, $frame['args']);
|
|
||||||
}
|
|
||||||
// We should again normalize the frames, because it might contain invalid items
|
|
||||||
$data['trace'][] = $this->toJson($this->normalize($frame), true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -390,21 +390,12 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$record = array('context' => array('exception' => $e));
|
$record = array('context' => array('exception' => $e));
|
||||||
$result = $formatter->format($record);
|
$result = $formatter->format($record);
|
||||||
|
|
||||||
$this->assertRegExp(
|
$this->assertSame(
|
||||||
'%"resource":"\[resource\] \(stream\)"%',
|
array(
|
||||||
$result['context']['exception']['trace'][0]
|
PHP_VERSION_ID < 50400 ? 'Monolog\Formatter\{closure}' : 'Monolog\Formatter\NormalizerFormatterTest->Monolog\Formatter\{closure}',
|
||||||
);
|
__FILE__.':'.(__LINE__-12),
|
||||||
|
),
|
||||||
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
|
array_slice($result['context']['exception']['trace'], 0, 2)
|
||||||
$pattern = '%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%';
|
|
||||||
} else {
|
|
||||||
$pattern = '%\\\\"foo\\\\":null%';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that the wrapped resource is ignored while encoding, only works for PHP <= 5.4
|
|
||||||
$this->assertRegExp(
|
|
||||||
$pattern,
|
|
||||||
$result['context']['exception']['trace'][0]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +412,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
$result = $formatter->format($record);
|
$result = $formatter->format($record);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'{"function":"throwHelper","class":"Monolog\\\\Formatter\\\\NormalizerFormatterTest","type":"->","args":["[object] (Monolog\\\\Formatter\\\\TestInfoLeak)","'.$dt->format('Y-m-d H:i:s').'"]}',
|
'Monolog\\Formatter\\NormalizerFormatterTest->throwHelper',
|
||||||
$result['context']['exception']['trace'][0]
|
$result['context']['exception']['trace'][0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
if (isset($frame['file'])) {
|
if (isset($frame['file'])) {
|
||||||
$data[] = $frame['file'].':'.$frame['line'];
|
$data[] = $frame['file'].':'.$frame['line'];
|
||||||
} else {
|
} else {
|
||||||
$data[] = json_encode($frame);
|
$data[] = (!empty($frame['class']) ? $frame['class'].$frame['type'] : '').$frame['function'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user