Uncategorized

Changing Laravel monolog timezone

I recently worked on a project where laravel logs were being uploaded to amazon cloudwatch . The problem was that the server time was set to UTC (which is correct), but laravel was recording the logs using the timestamp that was in the settings (which for me is incorrect, I have seen several places complaining about this approach) .

Well, to avoid having to rewrite the Log class, I changed it directly within the app/Providers/AppServiceProvider.php, changing the monolog timezone, as shown in the gist below.

<?php
namespace App\Providers;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
Log::setTimezone(new \DateTimeZone('UTC'));
$this->app->singleton(\Faker\Generator::class, function () {
return \Faker\Factory::create('pt_BR');
});
if ($this->app->environment() === "local") {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

Don’t forget to `php artisan config:cache` to reload settings

Leave a Reply

Your email address will not be published. Required fields are marked *


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/samu/public_html/blog/wp-includes/functions.php on line 4757