1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-30 18:00:17 +02:00

Merge branch '1.x'

This commit is contained in:
Jordi Boggiano
2019-08-30 10:39:21 +02:00
5 changed files with 5 additions and 68 deletions

View File

@@ -53,6 +53,7 @@
* 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 SignalHandler restarting syscalls functionality
* Fixed normalizers handling of exception backtraces to avoid serializing arguments in some cases
* Fixed ZendMonitorHandler to work with the latest Zend Server versions
### 1.24.0 (2018-11-05)

View File

@@ -178,12 +178,6 @@ 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);
}
}
}

View File

@@ -211,23 +211,6 @@ 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}') {
// Simplify closures handling
$data['trace'][] = $frame['function'];
} else {
if (isset($frame['args'])) {
// 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 \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, $depth + 1), true);
}
}
@@ -379,12 +362,12 @@ class NormalizerFormatter implements FormatterInterface
return $date->format($this->dateFormat);
}
protected function addJsonEncodeOption($option)
{
$this->jsonEncodeOptions |= $option;
}
protected function removeJsonEncodeOption($option)
{
$this->jsonEncodeOptions ^= $option;

View File

@@ -412,46 +412,7 @@ class NormalizerFormatterTest extends TestCase
$result = $formatter->format($record);
$this->assertSame(
'{"function":"Monolog\\\\Formatter\\\\{closure}","class":"Monolog\\\\Formatter\\\\NormalizerFormatterTest","type":"->","args":["[object] (Monolog\\\\Formatter\\\\TestFooNorm)","[resource(stream)]"]}',
$result['context']['exception']['trace'][0]
);
}
/**
* This test was copied from `testExceptionTraceWithArgs` in order to ensure that pretty prints works
*/
public function testPrettyPrint()
{
try {
// This will contain $resource and $wrappedResource as arguments in the trace item
$resource = fopen('php://memory', 'rw+');
fwrite($resource, 'test_resource');
$wrappedResource = new TestFooNorm;
$wrappedResource->foo = $resource;
// Just do something stupid with a resource/wrapped resource as argument
$arr = [$wrappedResource, $resource];
// modifying the array inside throws a "usort(): Array was modified by the user comparison function"
usort($arr, function ($a, $b) {
throw new \ErrorException('Foo');
});
} catch (\Throwable $e) {
}
$formatter = new NormalizerFormatter();
$record = ['context' => ['exception' => $e]];
$formatter->setJsonPrettyPrint(true);
$result = $formatter->format($record);
$this->assertSame(
'{
"function": "Monolog\\\\Formatter\\\\{closure}",
"class": "Monolog\\\\Formatter\\\\NormalizerFormatterTest",
"type": "->",
"args": [
"[object] (Monolog\\\\Formatter\\\\TestFooNorm)",
"[resource(stream)]"
]
}',
__FILE__.':'.(__LINE__-9),
$result['context']['exception']['trace'][0]
);
}
@@ -489,7 +450,7 @@ class NormalizerFormatterTest extends TestCase
$result = $formatter->format($record);
$this->assertSame(
'{"function":"throwHelper","class":"Monolog\\\\Formatter\\\\NormalizerFormatterTest","type":"->","args":["[object] (Monolog\\\\Formatter\\\\TestInfoLeak)","'.$dt->format('Y-m-d\TH:i:sP').'"]}',
__FILE__ .':'.(__LINE__-9),
$result['context']['exception']['trace'][0]
);
}

View File

@@ -29,8 +29,6 @@ class ScalarFormatterTest extends \PHPUnit\Framework\TestCase
foreach ($trace as $frame) {
if (isset($frame['file'])) {
$data[] = $frame['file'].':'.$frame['line'];
} else {
$data[] = json_encode($frame);
}
}