Skip to content

Commit eed3745

Browse files
authored
Merge pull request #221 from opcodesio/feature/custom-timezone-for-viewing-logs
add the ability to set a time zone for Log Viewer UI
2 parents 938c314 + fb0b02a commit eed3745

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opcodesio/log-viewer",
3-
"version": "v2.3.2",
3+
"version": "v2.4.0",
44
"description": "Fast and easy-to-use log viewer for your Laravel application",
55
"keywords": [
66
"arukompas",

config/log-viewer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@
5050

5151
'back_to_system_label' => null, // Displayed by default: "Back to {{ app.name }}"
5252

53+
/*
54+
|--------------------------------------------------------------------------
55+
| Log Viewer time zone.
56+
|--------------------------------------------------------------------------
57+
| The time zone in which to display the times in the UI. Defaults to
58+
| the application's timezone defined in config/app.php.
59+
|
60+
*/
61+
62+
'timezone' => null,
63+
5364
/*
5465
|--------------------------------------------------------------------------
5566
| Log Viewer route middleware.

src/Log.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public function __construct(
5050
$firstLineSplit = str_split($firstLine, 1000);
5151
preg_match(LogViewer::laravelRegexPattern(), array_shift($firstLineSplit), $matches);
5252

53-
$this->time = Carbon::parse($matches[1])->tz(config('app.timezone', 'UTC'));
53+
$this->time = Carbon::parse($matches[1])->tz(
54+
config('log-viewer.timezone', config('app.timezone', 'UTC'))
55+
);
5456

5557
// $matches[2] contains microseconds, which is already handled
5658
// $matches[3] contains timezone offset, which is already handled

tests/Unit/LogTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,14 @@
104104
assertEquals('production', $log->environment);
105105
assertEquals('', $log->fullText);
106106
});
107+
108+
it('can set a custom timezone of the log entry', function () {
109+
$text = '[2022-11-07 17:51:33] production.ERROR: test message';
110+
config(['log-viewer.timezone' => $tz = 'Europe/Vilnius']);
111+
112+
$log = new Log(0, $text, 'laravel.log', 0);
113+
114+
assertEquals($tz, $log->time->timezoneName);
115+
$expectedTime = \Carbon\Carbon::parse('2022-11-07 17:51:33', 'UTC')->tz($tz)->toDateTimeString();
116+
assertEquals($expectedTime, $log->time->toDateTimeString());
117+
});

0 commit comments

Comments
 (0)