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

Better PSR-3 message formatting

This commit is contained in:
Lars Strojny
2017-04-13 00:06:26 +02:00
parent 71afce5df7
commit 85d49f8568
2 changed files with 8 additions and 2 deletions

View File

@@ -20,7 +20,7 @@ namespace Monolog\Processor;
*/
class PsrLogMessageProcessor
{
const SIMPLE_DATE = "Y-m-d\TH:i:sP";
const SIMPLE_DATE = "Y-m-d\TH:i:s.uP";
private $dateFormat;
@@ -60,6 +60,8 @@ class PsrLogMessageProcessor
$replacements[$placeholder] = $val->format($this->dateFormat);
} elseif (is_object($val)) {
$replacements[$placeholder] = '[object '.get_class($val).']';
} elseif (is_array($val)) {
$replacements[$placeholder] = 'array'.@json_encode($val);
} else {
$replacements[$placeholder] = '['.gettype($val).']';
}

View File

@@ -68,7 +68,11 @@ class PsrLogMessageProcessorTest extends \PHPUnit\Framework\TestCase
[false, ''],
[$date, $date->format(PsrLogMessageProcessor::SIMPLE_DATE)],
[new \stdClass, '[object stdClass]'],
[[], '[array]'],
[[], 'array[]'],
[[], 'array[]'],
[[1, 2, 3], 'array[1,2,3]'],
[['foo' => 'bar'], 'array{"foo":"bar"}'],
[stream_context_create(), '[resource]'],
];
}
}