The best Android logger for file entry

What is the best registration structure that works great on Android to write text to a file?

I tried using SLF4J-android but 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 slf4j-android-1.6.1-RC1.jar to the build path

What is the problem?

+5
source share
2 answers

slf4j-androidonly supports logging before logcatand thus skips several classes from the regular SLF4J bar. If you want to use logback to enter the file, you will need the jar (not slf4j-android) and APIlogback-android . Are you looking for FileAppenderor RollingFileAppender.

Instruction:

  • Add slf4j-api-<version>.jarand logback-android-<version>.jarto your classpath.

  • assets/logback.xml ( AndroidManifest.xml... . ), :

<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>
</configuration>

. SD, WRITE_EXTERNAL_STORAGE. , .

Java-, SLF4J, DEBUG DEBUG /sdcard/testFile.log.

+16

"libs" .

+2

All Articles