Send non-fatal errors to Firebase Crashlytics with Sensible Logging

Christian
Volvo Car Mobility Tech
2 min readJan 26, 2023

--

Recording caught exceptions to Firebase is a great way to stay on-top of your app’s health as it’s running in production. Especially when paired up with notifications about spiking or new issues. Read more about them in the Firebase documentation

Let’s look at how you can report non-fatal errors using Sensible Logging.

First, we create a Channel implementation. Channels is how you hook up Sensible Logging to the different sinks you want your log statements to end up in.

Here, we simply call Crashlytics’s log() method for everything we receive to our print() method and if there is an exception in the log-line, we log that using recordException() as well.

We choose to use a ReleaseChannel since the code is meant to be used in release builds.

It’s also worth noting that if there’s no exception attached to the log message, there will be no resulting entry in Firebase console. But when an exception do get logged, the previously logged messages will be included.

About that Filter 🧐

In its current form, the filter will only allow error messages through.

Let’s fix that.

We can use the infix or function to combine our level filter together with a Category filter that allows a few select categories through.

This should allow us some more context while viewing the non-fatal in Firebase

Default versus non-default Channels

We’ve set our channels default parameter to true. Meaning that our print method will receive every log statement that passes the filter.

An option to allow a bit more fine grained control over what gets sent to Crashlytics is to set the default parameter to false. Then we have to pass the Channel ID everytime we want to send something to Firebase.

Log.e(“Something terrible happened”, exception, Channels.Crashlytics)

Typically, you combine this option with the AllowAll filter since the two concepts makes a complex mix.

Configuring based on build-type

Now, let’s configure Sensible Logging to pick up our newly created channel in release build. But in debug builds we keep using the LogCat channel. Here, I’ve modified the setup code from the Usage section of the README.

Wrapping up

That’s it for this post. Hopefully I have been able to convey how you can use Sensible Logging to ease logging to Firebase Crashlytics in your project.

Be sure to check out my previous post about Per developer log output with Sensible Logging.

--

--