mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 04:37:38 +02:00
Handle DateTime objects in formatted messages (#940)
* Handle DateTime objects in formatted meessages * Use interface to catch both DateTime and DateTimeImmutable * Maintain formatting standards. * Visibility to private.
This commit is contained in:
committed by
Jordi Boggiano
parent
f3dda67c09
commit
a0406bf8dd
@@ -27,8 +27,24 @@ class PsrLogMessageProcessorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $message['message']);
|
||||
}
|
||||
|
||||
public function testCustomDateFormat()
|
||||
{
|
||||
$format = "Y-m-d";
|
||||
$date = new \DateTime();
|
||||
|
||||
$proc = new PsrLogMessageProcessor($format);
|
||||
|
||||
$message = $proc([
|
||||
'message' => '{foo}',
|
||||
'context' => ['foo' => $date],
|
||||
]);
|
||||
$this->assertEquals($date->format($format), $message['message']);
|
||||
}
|
||||
|
||||
public function getPairs()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
|
||||
return [
|
||||
['foo', 'foo'],
|
||||
['3', '3'],
|
||||
@@ -36,6 +52,7 @@ class PsrLogMessageProcessorTest extends \PHPUnit_Framework_TestCase
|
||||
[null, ''],
|
||||
[true, '1'],
|
||||
[false, ''],
|
||||
[$date, $date->format(PsrLogMessageProcessor::SIMPLE_DATE)],
|
||||
[new \stdClass, '[object stdClass]'],
|
||||
[[], '[array]'],
|
||||
];
|
||||
|
Reference in New Issue
Block a user