rollbar / rollbar-php-laravel

Rollbar error monitoring integration for Laravel projects
https://docs.rollbar.com/docs/laravel
140 stars 39 forks source link

"Unable to create configured logger. Using emergency logger....NullHandler" error #150

Open shaifulborhan opened 1 year ago

shaifulborhan commented 1 year ago

Laravel 8.x PHP 8.1.x rollbar/rollbar-laravel v7.2.0

laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): NullHandler must be an instance of Monolog\\Handler\\HandlerInterface at /project/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:372)

My laravel.log file has been flooded with this error after updating PHP from 7.4.x to 8.1.x and rollbar/rollbar-laravel from 7.0.0 to 7.2.0.

I followed the installation here https://docs.rollbar.com/docs/laravel#laravel-6-through-9 but nothing needs to be updated as far as I am concerned because my Laravel version doesn't change.

Please advise.

danielmorell commented 1 year ago

I am not sure why you are getting that error. NullHandler is a part of monolog/monolog itself and is an instance of the Monolog\Handler\HandlerInterface interface.

I can offer a couple possibilities but none of them seem like a clear option.

  1. Your cached config could be stale. Try running php artisan config:cache.
  2. You somehow have two versions of monolog/monolog available in your environment. Try running composer update monolog/monolog followed by composer dump.
  3. You have a NullHandler object in another package and accidentally, imported that instead of Monolog\Handler\NullHandler.

If none of those seem to resolve the issue and you still can't figure it out, please post the exact version installed for the following packages...

  1. rollbar/rollbar
  2. rollbar/rollbar-laravel
  3. monolog/monolog
  4. laravel/framework
vbezruchkin commented 1 year ago

Hello,

I have the same issue. I just followed the correct instructions:

[2023-03-15 22:07:20] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Rollbar\\Laravel\\MonologHandler must be an instance of Monolog\\Handler\\HandlerInterface at /.../vendor/laravel/framework/src/Illuminate/Log/LogManager.php:384)

Latest versions of the libraries + Laravel 10.

This can help:

https://laravel.com/docs/10.x/upgrade#monolog-3

danielmorell commented 1 year ago

@vbezruchkin what version of rollbar/rollbar-laravel are you using?

beltranbot commented 1 year ago

Had this same issue occur to me using the following versions:

After closely reviewing the issue I noticed that I accidentally had set up the environment variable as ROLLBAR_token instead of ROLLBAR_TOKEN . So just be aware that this misconfiguration can result in this very same error.

jpylisela commented 11 months ago

Same issue here, please advise.

PHP v8.1.23

rollbar/rollbar 4.0.1 rollbar/rollbar-laravel 8.0.0 monolog/monolog 3.4.0 laravel/framework 10.24.0

My ROLLBAR_TOKEN is set correctly in the .env

The error is slightly different:

[2023-09-29 13:56:32] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (Illuminate\\Contracts\\Container\\BindingResolutionException(code: 0): Unresolvable dependency resolving [Parameter #0 [ <required> array $config ]] in class Rollbar\\RollbarLogger

I looked into the Monolog upgrade instructions, but I can't immediately see anything that's relevant for the setup:

https://laravel.com/docs/10.x/upgrade#monolog-3

Current implementation:

    'channels' => [
        'stack' => [
            'driver'            => 'stack',
            'channels'          => ['rollbar', 'single'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path'   => storage_path('logs/laravel.log'),
            'level'  => env('LOG_LEVEL', 'debug'),
        ],

        'rollbar' => [
            'driver'       => 'monolog',
            'handler'      => \Rollbar\Laravel\MonologHandler::class,
            'access_token' => env('ROLLBAR_TOKEN'),
            'environment'  => env('APP_NAME', 'production'),
            'level'        => 'warning',
        ],
danielmorell commented 10 months ago

It is possible this could be related to an autoloading issue. Try running...

composer dump
jpylisela commented 10 months ago

It is possible this could be related to an autoloading issue. Try running...

composer dump

Did not fix it for me unfortunately.