Skip to content

Commit b56feb2

Browse files
committed
fix the bug when file contains an empty log entry
1 parent 1440ef1 commit b56feb2

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

resources/views/livewire/log-list.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
>
77
<div class="flex flex-col h-full w-full mx-3 mb-4">
88
<div class="px-4 mb-4 flex items-start">
9-
<div class="flex-1 flex items-center mr-6">
9+
<div class="flex items-center mr-6">
1010
@if(isset($showLevelsDropdown) && $showLevelsDropdown)
1111
<div>@include('log-viewer::partials.log-list-level-buttons')</div>
1212
@endif

src/Log.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function __construct(
3838
$this->index = $index;
3939
$this->fileIdentifier = $fileIdentifier;
4040
$this->filePosition = $filePosition;
41+
$text = mb_convert_encoding(rtrim($text, "\t\n\r"), 'UTF-8', 'UTF-8');
4142
$this->fullTextLength = strlen($text);
42-
$text = mb_convert_encoding(trim($text), 'UTF-8', 'UTF-8');
4343

4444
$matches = [];
4545
[$firstLine, $theRestOfIt] = explode("\n", Str::finish($text, "\n"), 2);

tests/Unit/ProcessingLaravelLogEntriesTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,14 @@
9393
['iNfO', Level::Info],
9494
['', Level::None],
9595
]);
96+
97+
it('handles missing message', function () {
98+
$text = "[2022-11-07 17:51:33] production.ERROR: ";
99+
100+
$log = new Log(0, $text, 'laravel.log', 0);
101+
102+
assertEquals('2022-11-07 17:51:33', $log->time?->toDateTimeString());
103+
assertEquals(Level::Error, $log->level->value);
104+
assertEquals('production', $log->environment);
105+
assertEquals('', $log->fullText);
106+
});

0 commit comments

Comments
 (0)