# Timber — Extensible Logging Utility for Android > A small, extensible logging API for Android by Jake Wharton that improves on the standard Log class with automatic tag generation, pluggable log trees, and production-safe defaults. ## Install Save in your project root: # Timber — Extensible Logging Utility for Android ## Quick Use ```gradle implementation 'com.jakewharton.timber:timber:5.0.1' ``` ```kotlin // Initialize in Application.onCreate if (BuildConfig.DEBUG) { Timber.plant(Timber.DebugTree()) } // Log from anywhere without a TAG Timber.d("User %s logged in", username) Timber.e(exception, "Failed to load data") ``` ## Introduction Timber is a logging utility for Android created by Jake Wharton that wraps the standard android.util.Log class with a more ergonomic API. It automatically generates log tags from the calling class name, supports string formatting, and uses a tree-based architecture that lets developers plug in different logging behaviors for debug and release builds. ## What Timber Does - Provides a static logging API that eliminates the need to define TAG constants in every class - Automatically generates log tags from the calling class name in debug builds - Uses a tree-based plugin system where different Tree implementations handle log output - Supports format-string arguments and throwable parameters in a single call - Enables conditional logging by planting trees only in specific build configurations ## Architecture Overview Timber's architecture centers on the Forest pattern: a static list of Tree objects that receive every log call. When Timber.d() or Timber.e() is called, the message is dispatched to all planted trees. DebugTree logs to Logcat with an auto-generated tag derived from the call stack. Custom trees can route logs to crash reporting services, file storage, or remote analytics. Trees can filter by priority, tag, or message content. ## Setup & Configuration - Add the Timber dependency to your module-level build.gradle - Plant a DebugTree in your Application.onCreate for debug builds - Create custom Tree subclasses for release logging (e.g., sending errors to Crashlytics) - Use Timber.tag("custom") to override the auto-generated tag for specific log calls - Call Timber.uprootAll() to remove all trees, useful for test setup and teardown ## Key Features - Automatic tag generation from the calling class name, removing TAG boilerplate - Tree-based plugin architecture for routing logs to different destinations per build type - Format-string support with varargs for readable log calls without string concatenation - Lint checks that warn against direct android.util.Log usage when Timber is available - Tiny library with zero dependencies beyond the Android framework ## Comparison with Similar Tools - **android.util.Log** — built-in Android logging; Timber adds auto-tags, formatting, and pluggable destinations - **Logger** — another logging library with pretty-printing; Timber is lighter and more widely adopted - **SLF4J + Logback** — Java logging facade; Timber is Android-specific with a simpler API - **Loguru (Python)** — similar philosophy of making logging simple; Timber serves the same role for Android - **Stetho** — Facebook debug bridge with log inspection; Timber focuses on the logging API rather than inspection tooling ## FAQ **Q: How do I send crash logs to Crashlytics in production?** A: Create a custom Tree that overrides log() and calls FirebaseCrashlytics.getInstance().recordException() for error-level messages, then plant it only in release builds. **Q: Does Timber work with Kotlin coroutines?** A: Yes. Timber's static API is thread-safe and works from any coroutine context or thread. **Q: Will auto-tag generation affect performance in release builds?** A: DebugTree uses stack trace inspection for tags, which has minor overhead. In release builds, plant a custom tree that uses a fixed tag to avoid this cost. **Q: Can I use Timber in a multi-module project?** A: Yes. Plant trees in the Application class, and all modules can call Timber's static methods. The tree architecture ensures consistent logging behavior across modules. ## Sources - https://github.com/JakeWharton/timber - https://jakewharton.com/timber/ --- Source: https://tokrepo.com/en/workflows/asset-13e2a634 Author: AI Open Source