8000 bug #42600 [HttpKernel] Fix timestamp_rfc3339 in LoggerDataCollector … · symfony/symfony@dabd127 · GitHub
[go: up one dir, main page]

Skip to content

Commit dabd127

Browse files
committed
bug #42600 [HttpKernel] Fix timestamp_rfc3339 in LoggerDataCollector (carlcasbolt)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] Fix timestamp_rfc3339 in LoggerDataCollector Found that this was still needed for some log items to avoid an error in Profiler | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Ticket | Fixes #42622 | License | MIT Fix for the following error on Web Profiler when looking at error logs ``` [2021-08-17T10:30:06.093284+00:00] request.CRITICAL: Uncaught PHP Exception Twig\Error\RuntimeError: "An exception has been thrown during the rendering of a template ("Warning: Undefined array key "timestamp_rfc3339"")." at /app/vendor/symfony/web-profiler-bundle/Resources/views/Collector/logger.html.twig line 49 {"exception":"[object] (Twig\\Error\\RuntimeError(code: 0): An exception has been thrown during the rendering of a template (\"Warning: Undefined array key \"timestamp_rfc3339\"\"). at /app/vendor/symfony/web-profiler-bundle/Resources/views/Collector/logger.html.twig:49)\n[previous exception] [object] (ErrorException(code: 0): Warning: Undefined array key \"timestamp_rfc3339\" at /app/vendor/symfony/http-kernel/DataCollector/LoggerDataCollector.php:112)"} [] ``` Found this issue on a new 5.4 project build today Expected data shape is ``` array:7 [▼ "timestamp" => Symfony\Component\VarDumper\Cloner\Data {#2810 ▶} "timestamp_rfc3339" => Symfony\Component\VarDumper\Cloner\Data {#2622 ▶} "message" => Symfony\Component\VarDumper\Cloner\Data {#2811 ▶} "priority" => Symfony\Component\VarDumper\Cloner\Data {#2812 ▶} "priorityName" => Symfony\Component\VarDumper\Cloner\Data {#2813 ▶} "context" => Symfony\Component\VarDumper\Cloner\Data {#2814 ▶} "channel" => Symfony\Component\VarDumper\Cloner\Data {#2815 ▶} ] ``` However I'm seeing this shape for `Please install the "intl" PHP extension for best performance.` ``` array:8 [▼ "message" => Symfony\Component\VarDumper\Cloner\Data {#2905 ▶} "context" => Symfony\Component\VarDumper\Cloner\Data {#2717 ▶} "timestamp" => Symfony\Component\VarDumper\Cloner\Data {#2906 ▶} "priority" => Symfony\Component\VarDumper\Cloner\Data {#2907 ▶} "priorityName" => Symfony\Component\VarDumper\Cloner\Data {#2908 ▶} "channel" => Symfony\Component\VarDumper\Cloner\Data {#2909 ▶} "scream" => Symfony\Component\VarDumper\Cloner\Data {#2910 ▶} "errorCount" => Symfony\Component\VarDumper\Cloner\Data {#2911 ▶} ] ``` ![image](https://user-images.githubusercontent.com/1097038/129744965-3cb18a81-5083-446d-af7e-d1209dde9eb5.png) Commits ------- 967dee3 [HttpKernel] Fix timestamp_rfc3339 in LoggerDataCollector
2 parents bf8ecc4 + 967dee3 commit dabd127

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ private function getContainerDeprecationLogs(): array
208208
$logs = [];
209209
foreach (unserialize($logContent) as $log) {
210210
$log['context'] = ['exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])];
211-
$log['timestamp'] = (new \DateTimeImmutable())->setTimestamp($bootTime)->format(\DateTimeInterface::RFC3339_EXTENDED);
211+
$log['timestamp'] = $bootTime;
212+
$log['timestamp_rfc3339'] = (new \DateTimeImmutable())->setTimestamp($bootTime)->format(\DateTimeInterface::RFC3339_EXTENDED);
212213
$log['priority'] = 100;
213214
$log['priorityName'] = 'DEBUG';
214215
$log['channel'] = null;

src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\HttpFoundation\Response;
1919
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
2020
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
21+
use Symfony\Component\VarDumper\Cloner\Data;
2122

2223
class LoggerDataCollectorTest extends TestCase
2324
{
@@ -45,6 +46,52 @@ public function testCollectWithUnexpectedFormat()
4546
], $compilerLogs['Unknown Compiler Pass']);
4647
}
4748

49+
public function testCollectFromDeprecationsLog()
50+
{
51+
$containerPathPrefix = __DIR__.'/';
52+
$path = $containerPathPrefix.'Deprecations.log';
53+
touch($path);
54+
file_put_contents($path, serialize([[
55+
'type' => 16384,
56+
'message' => 'The "Symfony\Bundle\FrameworkBundle\Controller\Controller" class is deprecated since Symfony 4.2, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.',
57+
'file' => '/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php',
58+
'line' => 17,
59+
'trace' => [[
60+
'file' => '/home/hamza/projet/contrib/sf/src/Controller/DefaultController.php',
61+
'line' => 9,
62+
'function' => 'spl_autoload_call',
63+
]],
64+
'count' => 1,
65+
]]));
66+
67+
$logger = $this
68+
->getMockBuilder(DebugLoggerInterface::class)
69+
->setMethods(['countErrors', 'getLogs', 'clear'])
70+
->getMock();
71+
72+
$logger->expects($this->once())->method('countErrors')->willReturn(0);
73+
$logger->expects($this->exactly(2))->method('getLogs')->willReturn([]);
74+
75+
$c = new LoggerDataCollector($logger, $containerPathPrefix);
76+
$c->lateCollect();
77+
78+
$processedLogs = $c->getProcessedLogs();
79+
80+
$this->assertCount(1, $processedLogs);
81+
82+
$this->assertEquals($processedLogs[0]['type'], 'deprecation');
83+
$this->assertEquals($processedLogs[0]['errorCounter'], 1);
84+
$this->assertEquals($processedLogs[0]['timestamp'], (new \DateTimeImmutable())->setTimestamp(filemtime($path))->format(\DateTimeInterface::RFC3339_EXTENDED));
85+
$this->assertEquals($processedLogs[0]['priority'], 100);
86+
$this->assertEquals($processedLogs[0]['priorityName'], 'DEBUG');
87+
$this->assertNull($processedLogs[0]['channel']);
88+
89+
$this->assertInstanceOf(Data::class, $processedLogs[0]['message']);
90+
$this->assertInstanceOf(Data::class, $processedLogs[0]['context']);
91+
92+
@unlink($path);
93+
}
94+
4895
public function testWithMainRequest()
4996
{
5097
$mainRequest = new Request();

0 commit comments

Comments
 (0)
0