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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
} |
Don’t forget to `php artisan config:cache` to reload settings