Laravel 8.x Is there any way to bind CustomLogger using monolog with DateTimeZone set via Service Providers

Viewed 61

I'd like to override all of Laravel logger's dateTimeZone to 'Asia/Tokyo', but not changing config/app.php => timezone.

Laravel comes with monolog library by default, and basically Illuminate\Log\LogManager is doing all the work to instantiate Monolog\Logger objects.

We can pass DateTimeZone object to Monolog\Logger constructor's 4th argument, but there is no way we can pass that to LogManager via config/logging.php or anything.

I know that there's a way to create custom logger object with full control and register to custom channel. https://laravel.com/docs/8.x/logging#creating-custom-channels-via-factories

One way is that I'll create & use App\Logging\CreateCustomLoggerWithTokyoTimeZone::class and modify all of the default existing channels.

The other way is that I'll somehow override LogManager and bind it to service container 's log service. (override log service, but it's a singleton)

Any good ideas? Anything is appreciated.

0 Answers
Related