From b5c9a153d1d6f8d46f58db845504a5350aff9cf3 Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 4 Sep 2022 13:21:14 +0200 Subject: [PATCH] Improved display of logs --- composer.json | 3 ++- src/Parser/LineLogParser.php | 9 ++++----- .../views/themes/admin/logs/logs.html.twig | 16 +++------------- tests/LogFileTest.php | 9 ++++++--- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 4ff3be7..59cecd0 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "ext-json": "*", "ezsystems/ezplatform-admin-ui": "^2.3", "monolog/monolog": "^2.2", - "symfony/cache": "^5.2" + "symfony/cache": "^5.2", + "symfony/web-profiler-bundle": "^5.2" }, "require-dev": { "phpunit/phpunit": "^8.5.23" diff --git a/src/Parser/LineLogParser.php b/src/Parser/LineLogParser.php index fc2871b..24f8489 100644 --- a/src/Parser/LineLogParser.php +++ b/src/Parser/LineLogParser.php @@ -3,6 +3,7 @@ namespace IbexaLogsUi\Bundle\Parser; use Exception; +use Symfony\Component\VarDumper\Cloner\VarCloner; class LineLogParser { @@ -30,17 +31,15 @@ public function parse(string $log): array } } - // Json extract - $jsonContext = $matches['context'] === '[]' ? [] : json_decode($matches['context'], true, 2); - $jsonExtra = $matches['extra'] === '[]' ? [] : json_decode($matches['extra'], true, 2); + $cloner = new VarCloner(); return [ 'date' => $matches['date'], 'logger' => $matches['logger'], 'level' => $matches['level'], 'message' => $matches['message'], - 'context' => !$jsonContext && $jsonContext !== [] ? [$matches['context']] : $jsonContext, - 'extra' => !$jsonExtra && $jsonExtra !== [] ? [$matches['extra']] : $jsonExtra, + 'context' => $cloner->cloneVar(json_decode($matches['context'], true)), + 'extra' => $cloner->cloneVar(json_decode($matches['extra'], true)), ]; } catch (Exception $exception) { return []; diff --git a/src/Resources/views/themes/admin/logs/logs.html.twig b/src/Resources/views/themes/admin/logs/logs.html.twig index 004d68c..c75f1e5 100644 --- a/src/Resources/views/themes/admin/logs/logs.html.twig +++ b/src/Resources/views/themes/admin/logs/logs.html.twig @@ -92,30 +92,20 @@ - {{ log.message }} + {{ profiler_dump_log(log.message, log.context) }} {% if log.context is not empty or log.extra is not empty %}
{{ 'logs_ui.text.show_more'|trans }} {% if log.context is not empty %}
{{ 'logs_ui.text.context'|trans }}  - {% for key, value in log.context %} - - "{{ key }}" => - "{{ value is null ? 'null' : value }}" - - {% endfor %} + {{ profiler_dump(log.context, maxDepth=1) }}
{% endif %} {% if log.extra is not empty %}
{{ 'logs_ui.text.extra'|trans }}  - {% for key, value in log.extra %} - - "{{ key }}" => - "{{ value is null ? 'null' : value }}" - - {% endfor %} + {{ profiler_dump(log.extra, maxDepth=1) }}
{% endif %}
diff --git a/tests/LogFileTest.php b/tests/LogFileTest.php index 6cf6f1a..2af744c 100644 --- a/tests/LogFileTest.php +++ b/tests/LogFileTest.php @@ -4,6 +4,7 @@ use IbexaLogsUi\Bundle\LogManager\LogFile; use PHPUnit\Framework\TestCase; +use Symfony\Component\VarDumper\Cloner\VarCloner; class LogFileTest extends TestCase { @@ -45,13 +46,15 @@ public function testValidLogFileReadingAndParsing(): void $lines = $this->validLogFile->parse($lines); $this->assertIsArray($lines); $this->assertCount(32, $lines); - $this->assertSame([ + + $cloner = new VarCloner(); + $this->assertEquals([ 'date' => '2019-06-23 16:20:29', 'logger' => 'php', 'level' => 'INFO', 'message' => 'User Deprecated: Checking for the initialization of the "ezpublish.siteaccessaware.service.object_state" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0.', - 'context' => ['exception' => '[object] (ErrorException(code: 0): User Deprecated: Checking for the initialization of the "ezpublish.siteaccessaware.service.object_state" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0. at ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\DependencyInjection\\Container.php:364)'], - 'extra' => [], + 'context' => $cloner->cloneVar(['exception' => '[object] (ErrorException(code: 0): User Deprecated: Checking for the initialization of the "ezpublish.siteaccessaware.service.object_state" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0. at ezplatform\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\DependencyInjection\\Container.php:364)']), + 'extra' => $cloner->cloneVar([]), 'class' => 'info' ], $lines[0]); }