Laravel,  PHP

Customizando o timestamp do monolog


Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 11 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 13 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 14 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 31 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 33 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 34 in /home/samu/public_html/blog/wp-content/plugins/gistpress-master/includes/class-gistpress.php on line 473

Recentemente trabalhei em um projeto onde os logs do laravel estavam sendo enviados para o cloudwatch da amazon. O problema era que o horário do servidor estava setado em UTC (O que é o correto), porém o laravel estava gravando os logs utilizando o timestamp que estava nas configurções (o que pra mim é incorreto, já vi diversos lugares reclamando dessa abordagem).

Bom, para não ter que reescrever a classe de Log, alterei diretamente dentro do app/Providers/AppServiceProvider.php, alterando o timezone do monolog, conforme gist abaixo.

<?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

Não se esqueça depois de `php artisana config:cache` para recarregar as configurações

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *


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 5107