opcodesio / log-viewer

Fast and beautiful Log Viewer for Laravel
https://log-viewer.opcodes.io
MIT License
3.39k stars 237 forks source link

Fix Timezone Bug #335

Closed thotam closed 4 months ago

thotam commented 4 months ago

Fix Timezone always UTC

arukompas commented 4 months ago

Hey @thotam , can you explain what exactly is the bug?

thotam commented 4 months ago

Hey @thotam , can you explain what exactly is the bug?

Because when defined timezone in log-viewer.php file is NULL. The config('log-viewer.timezone', 'Value') always return NULL whatever the Value you set is. So $timezone = config('log-viewer.timezone', config('app.timezone', 'UTC')) ?? 'UTC'; will always is UTC Follow this docs

A default value may also be specified and will be returned if the configuration option does not exist

arukompas commented 4 months ago

hey @thotam I see! Thanks for explaining 😄

First of all, the timezone selection currently works as expected, even if the log viewer's timezone is set to null, because of the LogViewer::timezone() function taking care of defaulting to the app's timezone and finally to UTC. https://github.com/opcodesio/log-viewer/blob/65d945fc36ab12a2a7588539bac3c367c6b41e16/src/LogViewerService.php#L28-L37

And second, you're not supposed to use config() function inside config files, because Laravel does not guarantee any particular loading order for config files, and it could be that log-viewer.php is loaded before app.php is loaded, therefore not able to get the value.

This currently works as intended, so no change necessary. Closing.