-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Present log datetime in user timezone (#106)
- Loading branch information
1 parent
0a0393a
commit 6ba7367
Showing
28 changed files
with
273 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"src/main.ts": { | ||
"file": "assets/main-C7fre9xk.js", | ||
"file": "assets/main-BzT1BGZa.js", | ||
"name": "main", | ||
"src": "src/main.ts", | ||
"isEntry": true | ||
}, | ||
"style.css": { | ||
"file": "assets/style-BZSHBnOQ.css", | ||
"file": "assets/style-BECflOX-.css", | ||
"src": "style.css" | ||
} | ||
} |
18 changes: 9 additions & 9 deletions
18
src/Resources/public/assets/main-C7fre9xk.js → src/Resources/public/assets/main-BzT1BGZa.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...esources/public/assets/style-BZSHBnOQ.css → ...esources/public/assets/style-BECflOX-.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FD\LogViewer\Service\Serializer; | ||
|
||
use DateTime; | ||
use DateTimeZone; | ||
use FD\LogViewer\Entity\Index\LogRecord; | ||
use Psr\Log\LogLevel; | ||
|
||
class LogRecordsNormalizer | ||
{ | ||
// bootstrap 5 text colors | ||
private const LEVEL_CLASSES = [ | ||
LogLevel::DEBUG => 'text-info', | ||
LogLevel::INFO => 'text-info', | ||
LogLevel::NOTICE => 'text-info', | ||
LogLevel::WARNING => 'text-warning', | ||
LogLevel::ERROR => 'text-danger', | ||
LogLevel::ALERT => 'text-danger', | ||
LogLevel::CRITICAL => 'text-danger', | ||
LogLevel::EMERGENCY => 'text-danger', | ||
]; | ||
|
||
/** | ||
* @param LogRecord[] $records | ||
* | ||
* @return array{ | ||
* datetime: string, | ||
* level_name: string, | ||
* level_class: string, | ||
* channel: string, | ||
* text: string, | ||
* context: string|array<array-key, mixed>, | ||
* extra: string|array<array-key, mixed> | ||
* }[] | ||
*/ | ||
public function normalize(array $records, DateTimeZone $timeZone): array | ||
{ | ||
$date = new DateTime(timezone: $timeZone); | ||
$result = []; | ||
foreach ($records as $record) { | ||
$result[] = [ | ||
'datetime' => $date->setTimestamp($record->date)->format('Y-m-d H:i:s'), | ||
'level_name' => ucfirst($record->severity), | ||
'level_class' => self::LEVEL_CLASSES[$record->severity] ?? 'text-info', | ||
'channel' => $record->channel, | ||
'text' => $record->message, | ||
'context' => $record->context, | ||
'extra' => $record->extra, | ||
]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FD\LogViewer\Util; | ||
|
||
use DateTimeZone; | ||
use Exception; | ||
|
||
class DateUtil | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public static function tryParseTimezone(?string $timezone, string $default): DateTimeZone | ||
{ | ||
if ($timezone === null) { | ||
return new DateTimeZone($default); | ||
} | ||
|
||
try { | ||
return new DateTimeZone($timezone); | ||
} catch (Exception) { | ||
return new DateTimeZone($default); | ||
} | ||
} | ||
} |
Oops, something went wrong.