Skip to content

Instantly share code, notes, and snippets.

@kosiara
Created July 21, 2014 10:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kosiara/96f32978e24556eeef3a to your computer and use it in GitHub Desktop.
Save kosiara/96f32978e24556eeef3a to your computer and use it in GitHub Desktop.
Android slf4j logger with logcat + file; logging to file and logcat on Android
//Add slf4j dependencies in gradle
dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'com.github.tony19:logback-android-core:1.1.1-3'
compile 'com.github.tony19:logback-android-classic:1.1.1-3'
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class InitActivity {
public InitActivity() {
logger.debug("Activity loading....");
}
private static final Logger logger = LoggerFactory.getLogger(InitActivity.class);
}
<!-- Put this file in src/main/assets/logback.xml (your main assets folder) -->
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/sdcard/shant/shant.log</file> <!-- /sdcard/testFile.log -->
<append>true</append>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="LOGCAT" class="ch.qos.logback.classic.android.LogcatAppender">
<encoder>
<pattern>%-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE" />
<appender-ref ref="LOGCAT" />
</root>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment