Timber — A Logging Library for Android

Logging For Lazy People

Mustufa Ansari
Level Up Coding

--

In this article, I am gonna show you how you can get logs of your app on top of the Android default logs using Timber.

1) Timber

In your app, use the following syntax to get the logs.

Default Way:

Log.d(TAG, "something: ");

With Timber:

Timber.d("something Called");

In the default way, you always need to write TAG which could be anything like the name of your activity. But in timber, TAG will be defined by the library itself.

2) Adding Timber To Your App

In order to integrate timber into your app, it must be initialized when the app starts. So you need to create a base application class.

  1. Initlizied Timber in onCreate()
  2. Timber.DebugTree() print logs in debug mode.
  3. You can also add logs in the release mode of your app by just adding Timber.ReleaseTree() in onCreate().

Finally, it’s time to add this application class in AndroidManifest so that when the app launches, the application class will initialize first.

Now let’s head over to our MainActivity.java class and see the magic of Timber. I am just making it simple for learning purposes. You can add timber in your complex apps but for now, I am just getting logs using android lifecycle methods.

Let’s run the app and see what we will get in logcat.

You can see clearly the D/MainActivity: has added by the library itself as a TAG so that you will easily find the logs with respect to your activities.

--

--

📱Android/iOS Developer 🖋️ I Write For Mobile Developers 🎓 Tech Enthusiast