diff --git a/src/Logs/LaravelLog.php b/src/Logs/LaravelLog.php index 4a524ff6..cfe60deb 100644 --- a/src/Logs/LaravelLog.php +++ b/src/Logs/LaravelLog.php @@ -38,7 +38,9 @@ protected function parseText(array &$matches = []): void preg_match(static::regexPattern(), array_shift($firstLineSplit), $matches); - $this->datetime = Carbon::parse($matches[1], config('log-viewer.timezone', config('app.timezone', 'UTC'))); + $this->datetime = Carbon::parse($matches[1])?->setTimezone( + config('log-viewer.timezone', config('app.timezone', 'UTC')) ?? 'UTC' + ); // $matches[2] contains microseconds, which is already handled // $matches[3] contains timezone offset, which is already handled diff --git a/src/Logs/Log.php b/src/Logs/Log.php index 203c12e9..5a82e671 100644 --- a/src/Logs/Log.php +++ b/src/Logs/Log.php @@ -67,7 +67,10 @@ public static function matches(string $text, ?int &$timestamp = null, ?string &$ if ($result) { try { - $timestamp = static::parseDateTime($matches[static::$regexDatetimeKey] ?? null)?->timestamp; + $datetime = static::parseDateTime($matches[static::$regexDatetimeKey] ?? null); + $timezone = config('log-viewer.timezone', config('app.timezone', 'UTC')) ?? 'UTC'; + $timestamp = $datetime?->setTimezone($timezone)->timestamp; + $level = $matches[static::$regexLevelKey] ?? ''; } catch (\Exception $exception) { // not a valid datetime, so we can't match this log. Perhaps it's a different but similar log type. diff --git a/tests/Unit/LogTest.php b/tests/Unit/LogTest.php index ef2270d2..feb8f089 100644 --- a/tests/Unit/LogTest.php +++ b/tests/Unit/LogTest.php @@ -167,7 +167,7 @@ $log = new LaravelLog($text, 'laravel.log', 0, 0); assertEquals($tz, $log->datetime->timezoneName); - $expectedTime = \Carbon\Carbon::parse('2022-11-07 17:51:33', $tz)->toDateTimeString(); + $expectedTime = \Carbon\Carbon::parse('2022-11-07 17:51:33', 'UTC')->setTimezone($tz)->toDateTimeString(); assertEquals($expectedTime, $log->datetime->toDateTimeString()); });