Skip to content

sheungon/AndroidEasyLog

Repository files navigation

AndroidEasyLog

Download Codacy Badge License

A very lite weight Log library for Android.
Very easy to migrate from android Log to AndroidEasyLog.

Easily enable/disable logs in your app without changing much in your current codes.
It also shows code line number in the log.
Very convenient for tracing problems.

Example

01-27 12:18:35.086 15686-15686/com.sotwtm.log.sample D/Log: <15686>[(MainActivity.kt:96)#onClickLog] Clicked at : Fri Jan 27 12:18:35 GMT+08:00 2017

Integration

Gradle

implementation 'com.sotwtm.util:ec-log:1.0.0'

Usage

Enable/Disable Log with log level

// Show all logs
Log.logLevel = Log.VERBOSE
// Hide all logs
Log.logLevel = Log.NONE

Enable log for debug version only

Set the following in your application class onCreate method before any log.

//...
import com.sotwtm.util.Log

class M88Application : Application() {

    override fun onCreate() {
        //...
        Log.logLevel = if (BuildConfig.DEBUG) Log.VERBOSE else Log.NONE
        //...
    }
    //...
}

How to apply it to my existing project?

Simply replace with the following

import android.util.Log

with

import com.sotwtm.util.Log

More settings

Set default log TAG for all logs

We have all log methods taking one parameter (the log) only.
This can ease your pain on logging things.
To let multiple log TAG available, the android.util.Log 's two parameters methods is still there.

Log.defaultLogTag = "MyLogTag"
// Then, the following will be equivalent
Log.d("This is log")
android.util.Log("MyLogTag", "This is log")

Set action on logging wtf (What a Terrible Failure)

// This is the aciton will be taken on release build
Log.actionOnWtf = object : Log.OnWtfListener {  }
// This is the action will be taken on debug build
Log.actionOnWtfDebug = object : Log.OnWtfListener {  }

Notes

Disable log does not mean the log method won't be called.
So, for some logs that could take time. It is still recommended to skip the call to log.

if (Log.isDebuggable) {
   // Do only if the app is debuggable (loggable)
}

OR by removing them by prograud

-assumenosideeffects class com.sotwtm.util.Log {
    public static *** v(...);
    public static *** d(...);
    public static *** i(...);
    public static *** w(...);
    public static *** e(...);
    public static *** wtf(...);
}

Reference, Stackoverflow - Android Remove All Logging Calls

LICENSE

Apache License, version 2.0

About

Easily enable/disable logs in your app without changing much in your current codes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages