bugsnag / bugsnag-laravel

BugSnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
https://docs.bugsnag.com/platforms/php/laravel/
MIT License
876 stars 129 forks source link

Unhandled exceptions not reported to Bugsnag #412

Closed agasigp closed 4 years ago

agasigp commented 4 years ago

Expected behavior

Exceptions are sent to Bugsnag.

Observed behavior

Lumen cannot find the Bugsnag driver. This message is thrown in the log:

[2020-09-14 09:55:28] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined. at /home/agasigp/projects/web/lumen/vendor/illuminate/log/LogManager.php:192)
[stacktrace]
#0 /home/agasigp/projects/web/lumen/vendor/illuminate/log/LogManager.php(118): Illuminate\\Log\\LogManager->resolve()
#1 /home/agasigp/projects/web/lumen/vendor/illuminate/log/LogManager.php(98): Illuminate\\Log\\LogManager->get()
#2 /home/agasigp/projects/web/lumen/vendor/illuminate/log/LogManager.php(547): Illuminate\\Log\\LogManager->driver()
#3 /home/agasigp/projects/web/lumen/vendor/laravel/lumen-framework/src/Exceptions/Handler.php(56): Illuminate\\Log\\LogManager->error()
#4 /home/agasigp/projects/web/lumen/app/Exceptions/Handler.php(36): Laravel\\Lumen\\Exceptions\\Handler->report()
#5 /home/agasigp/projects/web/lumen/vendor/laravel/lumen-framework/src/Concerns/RegistersExceptionHandlers.php(103): App\\Exceptions\\Handler->report()
#6 /home/agasigp/projects/web/lumen/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(173): Laravel\\Lumen\\Application->sendExceptionToHandler()
#7 /home/agasigp/projects/web/lumen/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(108): Laravel\\Lumen\\Application->dispatch()
#8 /home/agasigp/projects/web/lumen/public/index.php(28): Laravel\\Lumen\\Application->run()
#9 /home/agasigp/.config/composer/vendor/cpriego/valet-linux/server.php(232): require('/home/agasigp/p...')
#10 {main}
"}

Steps to reproduce

I just make method in controller like this so it will throw FatalThrowableError syntax error :

public function index()
{
    return 'test'
}

Version

Additional information

imjoehaines commented 4 years ago

Hey @agasigp, it looks like all that's missing is a "default" log channel in your config/logging.php file

In our Lumen 6 example, there is a specified default channel which is used by the LogManager when it logs an error. The error message you're getting — "Log [] is not defined" — implies that there is no default, as the name of the channel should be in the square brackets

So adding a default channel to config/logging.php should fix your issue:

return [
    'default' => env('LOG_CHANNEL', 'stack'),

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single', 'bugsnag'],
        ],
        ...
        'bugsnag' => [
            'driver' => 'bugsnag',
        ],
    ],
];

I'd also generally recommend using stack as the log channel, rather than bugsnag. The bugsnag channel will only send reports to Bugsnag, whereas using stack will log errors to a file as well. Usually it's useful to have both, unless there's a specific reason why you only want errors reported to Bugsnag 🙂

agasigp commented 4 years ago

Thanks for the explanation. Issue solved.