I've implemented code for creating log file using slf4j in android but couldn't succeeded.
First I've added gradle dependency as per below:-
compile 'org.slf4j:slf4j-android:1.6.1-RC1'
compile 'com.github.tony19:logback-android-core:1.0.7-1'
Then as per the guidelines i created a configuration file in assets folder named as logback.xml
as per below :-
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/sdcard/testFile.log</file>
<append>true</append>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
Finally I add a log in my application like below:-
Logger logger = LoggerFactory.getLogger(HomeActivity.class);
logger.debug("Testing slf4j", "Hello world");
Now I ran this program and expecting the a log file there in SDcard but unfortunately no such file is seen. Please let me know if I am missing anything. If anybody have made it in android application, please help me out.
Thanks.
logback-android
requires slf4j-api
. slf4j-android
should not be used, as that's a standalone library that only redirects logs to logcat and does not process logback.xml
.
From logback-android
's GitHub page, the correct dependencies are:
dependencies {
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.github.tony19:logback-android:2.0.0'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With