What is the best logger framework which perfectly use in Android system for logging text into file?
I tried to use SLF4J-android but I got an exception
04-29 12:58:57.604: E/AndroidRuntime(372): java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
here is my code:
public class Main extends TabActivity {
private static final Logger log = LoggerFactory.getLogger(Main.class);
I added the slf4j-android-1.6.1-RC1.jar into build path
What will be the problem?
slf4j-android
only supports logging tologcat
and thus omits several classes from the regular SLF4J jar. If you want to use logback to log to a file, you need the API jar (notslf4j-android
) andlogback-android
. You're looking for theFileAppender
orRollingFileAppender
.Instructions:
Add
slf4j-api-<version>.jar
andlogback-android-<version>.jar
to your classpath.Create the file
assets/logback.xml
in your project (or use theAndroidManifest.xml
...see example), containing the following configuration:Note: Since the specified path is on SD, make sure to use
WRITE_EXTERNAL_STORAGE
permission. You can instead specify a different path where you already have write permissions.Your Java code, which contains the SLF4J logging calls, now logs all events at or above the
DEBUG
level to the/sdcard/testFile.log
.Make a folder named "libs" and put the jar inside that folder.