Skip to main content

Introduction to Timber Library

Introduction to Timber Library in Kotlin Android

Timber is a popular logging library for Android that provides a simple and flexible way to log messages in your Kotlin Android applications. It is designed to be easy to use and offers advanced features for logging and debugging.

In this tutorial, we will explore the features of Timber and learn how to install and use it in a Kotlin Android project.

Features of Timber

Timber offers several features that make it a powerful logging library for Android:

  1. Flexible logging levels: Timber allows you to define different logging levels such as VERBOSE, DEBUG, INFO, WARN, ERROR, and ASSERT. You can choose the appropriate level for each log message based on its importance and severity.

  2. Tagging log messages: Timber allows you to add tags to log messages, making it easier to identify and filter them. Tags can be used to group log messages based on specific components or areas of your application.

  3. Custom log output: Timber provides a default log output that prints log messages to the console. However, it also allows you to customize the log output based on your requirements. You can send log messages to a file, a remote server, or any other destination of your choice.

  4. Thread information: Timber automatically adds thread information to log messages, making it easier to track the execution flow of your application.

  5. Integration with Crashlytics: Timber seamlessly integrates with Crashlytics, a popular crash reporting tool for Android. You can log messages with Timber and have them automatically reported as non-fatal exceptions in Crashlytics.


To use Timber in your Kotlin Android project, follow these steps:

  1. Open your project in Android Studio.

  2. Open the build.gradle file of your app module.

  3. Add the following dependency to the dependencies block:

    implementation 'com.jakewharton.timber:timber:4.7.1'
  4. Sync the project to download the Timber library.


To start using Timber in your Kotlin Android project, follow these steps:

  1. In your Application class, initialize Timber in the onCreate method:

    class MyApplication : Application() {
    override fun onCreate() {
    if (BuildConfig.DEBUG) {
    // ...

    This will configure Timber to use the DebugTree implementation when the app is in debug mode.

  2. In your activity or fragment, import the Timber library:

    import timber.log.Timber
  3. You can now start logging messages using Timber. Here are some examples:

    Timber.d("Debug log message")
    Timber.i("Info log message")
    Timber.w("Warning log message")
    Timber.e("Error log message")

    By default, Timber will use the class name of the caller as the tag for log messages. You can also specify a custom tag by passing it as the first parameter:

    Timber.tag("CustomTag").d("Debug log message with custom tag")
  4. Run your application and check the logcat output in Android Studio. You should see the logged messages with the appropriate log level and tag.

Customizing Log Output

Timber allows you to customize the log output by creating your own log tree implementation. Here's an example:

class FileLoggingTree : Timber.Tree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
// Write log messages to a file
// ...

To use your custom log tree, plant it in your Application class:

if (BuildConfig.DEBUG) {

You can implement various log tree classes based on your requirements, such as sending log messages to a remote server or storing them in a database.

Timber Examples