My Timber Setup

Today I would like to show you the Timber setup that I am using in my projects.

Timber is an open-source logging library developed by Jake Wharton, which provides additional features on top of Android’s normal Log class. This library automatically provides Android’s Log class with the tag arguments based on the class name from which it was called allowing us to avoid creating annoying “LOG_TAG”s each time, whenever we want to log something. Also, it allows us to plant different logging Trees based on different situations (i.e. you can plant different Trees for debug and release versions of your app). Each logging Tree may change your logging behavior or provide you with additional features like storing logs in a persistent memory, sending logs via your crash reporting tool etc.

Summarizing the above, we can say that Timber gives you the possibility to manage your logging from one central place and enhances your logging experience with other additional features.

For this story I want to share my Tree classes used for different situations without going deeper into the implementation details. I will assume that you are already familiar with this library and know how to integrate it into your app. For those of you who need a refresher on its integration and features, I will recommend reading this article by Cauê Ferreira.

1. Debug Tree

This class provides following features:

a. Workaround for devices that doesn’t show lower priority logs;

b. Inserts line number of log statements into logs.

2. Release Tree

This class provides following configurations:

a. Prevents lower level logs from showing in logs;

b. Split log messages into lines to ensure each line can fit into Log’s max length

3. File Logging Tree

This class was developed based on codes provided by Vipin Kumar. Please check out his story for more details on file logging with Timber.

Hope you will find the above code snippets useful. Please share your feedback and comments.

Happy coding!