Clean and Concise Logging in Android

Wajid Ali
2 min readSep 8, 2021

--

Timber is a logging library created by JackWhatron on top of Android’s Log class. While in development, we usually end up writing a lot of log statements. And before release, we have to filter our logs, to see if there is any information that should not be logged in production is there.
If you want to create a log file for history and debugging, that could be very tricky while using Android’s Log class.
This tedious process can be avoided easily by using Timber.

Timber provides lots of other options as well. Let’s see how it can be used in our projects to maintain the logs better.

Integration of Timber

Add dependency in your build.gradle (app)
// timber
implementation 'com.jakewharton.timber:timber:4.7.1'

Create and connect your app class
Initizalize MyApplication class, and extend from Application class. Inside your application class, plant your debug and release trees to Timber like in example below:

Link MyApplication.kt in your Manifest.xml so that Android will know where to start with your app.

Most of the apps doesn’t need logging in production, skip adding Timber tree in production for this case.
But if you need to log information in your production build as well, like you may need to log some info (encryption recommended) to a file and later upload that file to server for troubleshooting issues that otherwise wouldn’t reproduce, then add a tree like below:

You are all setup at this point. And can print logs, from anywhere inside your application. For printing logs, consider following example,

Happy Logging…… 😀

Click 👏if you liked, anf follow for more to come.

--

--

Wajid Ali
Wajid Ali

Written by Wajid Ali

Android, iOS, Flutter, Augmented Reality and Technology enthusiast.

No responses yet