Skip to content

Gopinathp/sl4j_android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Why this project?

SL4J-Android is the log4j library ported for the Android platform which tries to bring our favourite logging framework to the Android. While using this library, typically, we would want to set warning level log on a production device and verbose level log during development. On the desktop log4j, we could pass this setting to the logger easily. But unfortunately, we cannot configure log4j android port as you would do it on in the regular desktop way. It relies on the standard Android's log level setup which unfortunately does not seem to work (http://stackoverflow.com/questions/2018263/android-logging/2019563#2019563). This project addresses this very problem.

How to use?

  • Download https://github.com/Gopinathp/sl4j_android/blob/master/bin/slf4j-android-logging-corrected.jar (or build your own jar from the sources provided in this project) and place the jar file inside the libs folder in your Android project.

  • On Applicaiton class, set the loglevel in a static block as shown below.

    static{
        if(BuildConfig.DEBUG) {
          	AndroidLoggerFactory.setLogLevel(Log.VERBOSE);
          } else {
        		AndroidLoggerFactory.setLogLevel(Log.ERROR);
        	}
    }
    
  • Create the logger object whereever you want by the standard logger way. Logger sLogger = LoggerFactory.getLogger(this.class.getSimpleName());

  • Add log statements in the standard log4j style.

    sLogger.debug("This is a debug message");
    sLogger.verbose("this is a verbose message");
    sLogger.error("Oh... This is an exception");
    sLogger.warn("This is a warning");
    

NOTE: This internally uses the android.util.Log's v,d,i,w,e methods() to do the actual logging.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages