Lumen logs not reported to Bugsnag

68 Views Asked by At

I have a Lumen 8 app where I want to use bugsnag to be notified when my app is logging some error.

I have followed the docs by:

  • Adding bugsnag/bugsnag-laravel module

  • Adding the service provider in my app.php

  • Adding the BUGSNAG_API_KEY in my .env file

  • Adding the bugsnag channel in my config/services.php file

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single', 'bugsnag'],
        ],
        'bugsnag' => [
            'driver' => 'bugsnag',
        ],
    ],
    
  • Adding this in the Exceptions/Handler.php file

    if (app()->bound('bugsnag') && $this->shouldReport($exception)) {
        Bugsnag::notifyException($exception);
    }
    

If I have an exception that is triggered by my app, it is reported correctly to my bugsnag dashboard (and I am notified by email), but if I have a log like Log::critical("something crashed"); the log is correctly written in my log file but nothing is sent to bugsnag.

Any idea what I am missing here?

Thank you for your help.

1

There are 1 best solutions below

0
Fabrice Lefloch On

I am able to send the errors to Bugsnag by creating my own LogServiceprovider and add this:

public function boot() { 
   Log::listen(function(MessageLogged $message){ 
     Bugsnag::notifyError($message->level, $message->message); 
   }); 
} 

But since nothing like this is mentioned in the documentation I'm wondering if this is the right way to handle this.