Framework: [6.0] Monolog Channel can't use NullHandler in Monolog 2.0

Created on 18 Sep 2019  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 6.0.3
  • PHP Version: 7.3

Description:

I used Monolog Channel with NullHandler on Laravel 5.8. It is worked fine.
But Laravel 6.0 throw following exception.

[2019-09-18 09:59:05] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (Error(code: 0): Call to undefined method Monolog\\Handler\\NullHandler::setFormatter() at /vagrant/server/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:376)
[stacktrace]
#0 /vagrant/server/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(347): Illuminate\\Log\\LogManager->prepareHandler(Object(Monolog\\Handler\\NullHandler), Array)
#1 /vagrant/server/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(185): Illuminate\\Log\\LogManager->createMonologDriver(Array)

I guess it is Monolog 1.x -> 2.0 compatibility problem.
Laravel 6.0 newly depend on Monolog 2.0 instead 1.x.

Illuminate/Log/LogManager.php use Monolog\Handler\HandlerInterface.
The interface has setFormatter() in Monolog 1.x (old).
However In Monolog 2.0, setFormatter() moved to Monolog\Handler\FormattableHandlerInterface.
LogManager must check FormattableHandlerInterface before call setFormatter() if there are Monolog 2.0.

Steps To Reproduce:

My config/logging.php is following.

'fluent' => [
    'driver'  => 'monolog',
    'level' => 'info',
    'handler' => env('FLUENTD_ENABLE', true) ? App\Logging\FluentdHandler::class : Monolog\Handler\NullHandler::class,
],
bug

Most helpful comment

I managed to reproduce this. Thanks for reporting. Appreciating a PR if you could whip one up.

All 3 comments

@driesvints
No. I use NullHandler as my custom monolog channel.
But I think that this null channel will occur the same problem.

I managed to reproduce this. Thanks for reporting. Appreciating a PR if you could whip one up.

Was this page helpful?
0 / 5 - 0 ratings