Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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) -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/sdcard/shant/shant.log</file> <!-- /sdcard/testFile.log -->
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
<appender name="LOGCAT" class="">
<pattern>%-5level %logger{36} - %msg%n</pattern>
<root level="DEBUG">
<appender-ref ref="FILE" />
<appender-ref ref="LOGCAT" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.