Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8aefe97

Browse filesBrowse files
bug #34601 [MonologBridge] Fix debug processor datetime type (mRoca)
This PR was merged into the 3.4 branch. Discussion ---------- [MonologBridge] Fix debug processor datetime type | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets |n/a | License | MIT | Doc PR | n/a This PR fixes an eventual `Call to a member function getTimestamp() on string` if any Processor transforms the `datetime` value, and uses the same record conditions as in the [ConsoleFormatter](https://github.com/symfony/monolog-bridge/blob/master/Formatter/ConsoleFormatter.php#L118 ) Commits ------- ffe3f10 [MonologBridge] Fix debug processor datetime type
2 parents 35b1328 + ffe3f10 commit 8aefe97
Copy full SHA for 8aefe97

File tree

2 files changed

+62
-1
lines changed
Filter options

2 files changed

+62
-1
lines changed

‎src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DebugProcessor implements DebugLoggerInterface
2222
public function __invoke(array $record)
2323
{
2424
$this->records[] = [
25-
'timestamp' => $record['datetime']->getTimestamp(),
25+
'timestamp' => $record['datetime'] instanceof \DateTimeInterface ? $record['datetime']->getTimestamp() : strtotime($record['datetime']),
2626
'message' => $record['message'],
2727
'priority' => $record['level'],
2828
'priorityName' => $record['level_name'],
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Monolog\Tests\Processor;
13+
14+
use Monolog\Logger;
15+
use PHPUnit\Framework\TestCase;
16+
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
17+
18+
class DebugProcessorTest extends TestCase
19+
{
20+
/**
21+
* @dataProvider providerDatetimeFormatTests
22+
*/
23+
public function testDatetimeFormat(array $record, $expectedTimestamp)
24+
{
25+
$processor = new DebugProcessor();
26+
$processor($record);
27+
28+
$records = $processor->getLogs();
29+
self::assertCount(1, $records);
30+
self::assertSame($expectedTimestamp, $records[0]['timestamp']);
31+
}
32+
33+
/**
34+
* @return array
35+
*/
36+
public function providerDatetimeFormatTests()
37+
{
38+
$record = $this->getRecord();
39+
40+
return [
41+
[array_merge($record, ['datetime' => new \DateTime('2019-01-01T00:01:00+00:00')]), 1546300860],
42+
[array_merge($record, ['datetime' => '2019-01-01T00:01:00+00:00']), 1546300860],
43+
[array_merge($record, ['datetime' => 'foo']), false],
44+
];
45+
}
46+
47+
/**
48+
* @return array
49+
*/
50+
private function getRecord()
51+
{
52+
return [
53+
'message' => 'test',
54+
'context' => [],
55+
'level' => Logger::DEBUG,
56+
'level_name' => Logger::getLevelName(Logger::DEBUG),
57+
'channel' => 'test',
58+
'datetime' => new \DateTime(),
59+
];
60+
}
61+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.