Skip to content

Commit

Permalink
Improved display of logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fkeloks committed Sep 4, 2022
1 parent 1ead843 commit b5c9a15
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions src/Parser/LineLogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace IbexaLogsUi\Bundle\Parser;

use Exception;
use Symfony\Component\VarDumper\Cloner\VarCloner;

class LineLogParser
{
Expand Down Expand Up @@ -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 [];
Expand Down
16 changes: 3 additions & 13 deletions src/Resources/views/themes/admin/logs/logs.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,20 @@
</div>
</td>
<td class="text-break">
<samp>{{ log.message }}</samp>
<samp>{{ profiler_dump_log(log.message, log.context) }}</samp>
{% if log.context is not empty or log.extra is not empty %}
<details class="mt-2">
<summary>{{ 'logs_ui.text.show_more'|trans }}</summary>
{% if log.context is not empty %}
<div class="mt-2">
<strong>{{ 'logs_ui.text.context'|trans }}&nbsp;</strong>
{% for key, value in log.context %}
<samp class="d-block mt-1">
"<span class="text-primary">{{ key }}</span>" =>
"<span class="text-primary">{{ value is null ? 'null' : value }}</span>"
</samp>
{% endfor %}
{{ profiler_dump(log.context, maxDepth=1) }}
</div>
{% endif %}
{% if log.extra is not empty %}
<div class="mt-2">
<strong>{{ 'logs_ui.text.extra'|trans }}&nbsp;</strong>
{% for key, value in log.extra %}
<samp class="d-block mt-1">
"<span class="text-primary">{{ key }}</span>" =>
"<span class="text-primary">{{ value is null ? 'null' : value }}</span>"
</samp>
{% endfor %}
{{ profiler_dump(log.extra, maxDepth=1) }}
</div>
{% endif %}
</details>
Expand Down
9 changes: 6 additions & 3 deletions tests/LogFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use IbexaLogsUi\Bundle\LogManager\LogFile;
use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Cloner\VarCloner;

class LogFileTest extends TestCase
{
Expand Down Expand Up @@ -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]);
}
Expand Down

0 comments on commit b5c9a15

Please sign in to comment.