Logging

The logging facility of the Gini Vision library for Android is based on SLF4j. The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time. This gives the App Developer the freedom of choice. If no SLF4J binding is found on the classpath, then SLF4J will default to a no-operation implementation.

The Gini Vision Library uses logging for debugging and error reporting at the moment.

Configuration

In order to use logging you have to add a SLF4J binding to the classpath of your app. If you wan’t to use logback for instance the logback dependencies must be present in the dependencies configuration of your build.gradle file.

 dependencies{
    ...
    compile 'com.github.tony19:logback-android-core:1.1.1-3'
    compile 'com.github.tony19:logback-android-classic:1.1.1-3'
    compile 'org.slf4j:slf4j-api:1.7.6'
    ...
}

Furthermore, logback itself must be configured. This can be done either via a groovy script (logback.groovy, a xml file (logback.xml) or directly in the application code. Here is a short example for configuring logback to append to the logcat logging facility.

final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.reset();

// setup LogcatAppender
final PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(lc);
layoutEncoder.setPattern("[%thread] %msg%n");
layoutEncoder.start();

final LogcatAppender logcatAppender = new LogcatAppender();
logcatAppender.setContext(lc);
logcatAppender.setEncoder(layoutEncoder);
logcatAppender.start();

final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.addAppender(logcatAppender);