Search code examples
laravelbugsnag

Bugsnag + Laravel: pass contextual information with Log::error?


When calling (Illuminate\Support\Facades\)Log::error I can only see the message on Bugsnag but not the contextual information. Is there a way I can set-up Laravel/Bugsnag to also pass context?

For example, when doing Log::error("Exception occurred.", ["Further info here."]); only the message ("Exception occurred.") is displayed on Bugsnag.


Solution

  • When you call Log::error the logged message and context are parsed by the Bugsnag PSR Logger. The uses the context in a few ways:

    1. Extracts a title from the context array if set. This title will then become the context in which your error is displayed on the Bugsnag dashboard.
    2. Extracts an exception from the context array if set. This exception will then be used to create the error report and stacktraces.
    3. Attaches the remaining context to the report as metadata. If the context array contains sub-arrays they will be displayed on separate tabs, if not the information will be displayed in a custom tab in the error on the Bugsnag dashboard.

    In your case, I would check out the custom metadata tab on your error and see if your context has turned up there.