Created
July 21, 2014 10:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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