Effortless Android Logging with Timber and Kotlin

Published: (January 8, 2026 at 03:49 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

What Makes Timber Special?

  • Concise and clean – a simple API that removes repetitive boilerplate.
  • Automatic tag generation – uses the calling class name as the tag, so you never hard‑code tags again.
  • Customizable trees – control where logs go (e.g., crash‑reporting tools, filtered by build type).
  • Production safety – logs are disabled by default in release builds, preventing accidental leakage of sensitive information.

Setting Up Timber in Your Android App

Step 1: Add the Dependency

// app‑level build.gradle
implementation 'com.jakewharton.timber:timber:5.0.1' // check for the latest version

Step 2: Initialize Timber in Your Application Class

Plant the appropriate tree as soon as the app starts.

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        } else {
            Timber.plant(ReleaseTree()) // custom tree for release builds
        }
    }
}

Declare the custom Application class in AndroidManifest.xml.

Step 3: Logging in Your Code

Replace the standard Log calls with Timber methods:

Timber.d("Debug message")
Timber.i("Info message")
Timber.w("Warning message")
Timber.e("Error message: %s", error)

// Using Kotlin string templates
Timber.d("User id: $userId")

All standard log levels (verbose, debug, info, warn, error) are supported.

Advanced Usage: Custom Trees and Extensions

Custom Trees

Define a tree to route logs to a crash‑reporting service (e.g., Firebase Crashlytics, Sentry):

class CrashReportingTree : Timber.Tree() {
    override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
        if (priority >= Log.WARN) {
            // Send the warning/error to your crash‑reporting backend
        }
    }
}

Plant this tree in release builds to capture only important logs.

Kotlin Extensions

Libraries such as timberkt add Kotlin‑idiomatic extensions. The lambda is evaluated only when the log will actually be printed, improving performance:

Timber.d { "User id: $userId, name: ${user.name}" }

Why Choose Timber?

  • No manual tags – automatic tag generation saves time and avoids mistakes.
  • Easy cleanup – a single line disables logging in release builds; no need to hunt down Log.d statements.
  • Customizable behavior – route logs to external services in production, keeping Logcat clean.
  • Rich metadata – includes class names, line numbers, etc., for more informative logs.

Final Thoughts

Timber is more than just another logging library; it’s a thoughtful enhancement to the Android development workflow. With concise syntax, automatic tagging, and customizable trees, logging becomes effortless while retaining full control and safety.

Give Timber a try the next time you reach for Log.d("TAG", "Some message")—it might just change the way you log forever.

Happy coding!

Back to Blog

Related posts

Read more »

RxJava Fundamentals - Reactive Programming on Android

RxJava의 기본 개념과 안드로이드에서의 활용법을 알아봅니다. RxJava란? RxJava는 Reactive + Functional Programming을 결합한 라이브러리입니다. 핵심 개념 - 데이터와 처리를 분리하고, 데이터는 처리에 푸시만 합니다. - Threading을 라이브러...