Skip to content

Timber + Logger Integration. Make Logcat Prettier, show thread information and more.

Notifications You must be signed in to change notification settings

androiddevnotesyoutube/pretty-timber-android-logcat

Repository files navigation

Pretty Timber Android Logcat


Timber + Logger Integration


Video Instructions: https://youtu.be/zoS_i8VshCk


Android Badge androiddevnotes GitHub badge


Timber Logger Integration awesomedevnotes - androiddevnotes youtube thumbnail


Code

App.kt

class App : Application() {
    override fun onCreate() {
        super.onCreate()

        val formatStrategy: FormatStrategy = PrettyFormatStrategy.newBuilder()
            .showThreadInfo(true) // (Optional) Whether to show thread info or not. Default true
            .methodCount(1) // (Optional) How many method line to show. Default 2
            .methodOffset(5) // Set methodOffset to 5 in order to hide internal method calls
            .tag("") // To replace the default PRETTY_LOGGER tag with a dash (-).
            .build()

        Logger.addLogAdapter(AndroidLogAdapter(formatStrategy))


        Timber.plant(object : Timber.DebugTree() {

            override fun log(
                priority: Int, tag: String?, message: String, t: Throwable?
            ) {
                Logger.log(priority, "-$tag", message, t)
            }
        })

        // Usage
        Timber.d("onCreate: Inside Application!")
    }
}

// Dependencies needed in build.gradle (app) file - Remember to update version if required.
// implementation 'com.orhanobut:logger:2.2.0'
// implementation 'com.jakewharton.timber:timber:4.7.1'

Dependencies

implementation 'com.jakewharton.timber:timber:4.7.1'

// https://github.com/JakeWharton/timber
implementation 'com.orhanobut:logger:2.2.0'

// https://github.com/orhanobut/logger

💻 Find us on

About

Timber + Logger Integration. Make Logcat Prettier, show thread information and more.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages