kenshin9 kenshin9 - 15 days ago 5
PHP Question

Laravel 5.1 Logger Timezone

Is there a way I can change the timezone for the Laravel 5.1 logger? I've seen previous discussions where they extended the Monolog class and updated the Service Provider, but that was for an older version of Laravel and it doesn't look like the

LogServiceProvider
is used anymore.

I see there's a
timezone
key in the
app.php
file, but I don't want the whole system to change. I just want to update the timezone for the logs, and keep the rest of the system in UTC.

Answer

I just saw your reply, I've figured it out and it's really simple. Create a new service provider and register it in config/app.php then add the following line to the boot method.

Logger::setTimezone(new \DateTimeZone('PST'));

Make sure you include the Logger class at the top of your service provider.

You may set the timezone to whichever one you'd like from this list, http://php.net/manual/en/timezones.php