用于登录到文件Android的最佳记录文件、Android

由网友(别来无恙你还狗模狗样)分享简介:什么是最好的记录器框架,这在Android系统完全用于记录文本文件?What is the best logger framework which perfectly use in Android system for logging text into file?我试图用SLF4J-机器人,但我得到了一个异常I...

什么是最好的记录器框架,这在Android系统完全用于记录文本文件?

What is the best logger framework which perfectly use in Android system for logging text into file?

我试图用SLF4J-机器人,但我得到了一个异常

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

这是我的code:

here is my code:

public class Main extends TabActivity {
    private static final Logger log = LoggerFactory.getLogger(Main.class); 

我添加了SLF4J-的Andr​​oid 1.6.1-RC1.jar到构建路径

I added the slf4j-android-1.6.1-RC1.jar into build path

会是什么问题?

推荐答案

SLF4J-机器人只支持记录到的logcat 从而省略了一些类从正规SLF4J罐子。如果你想使用的logback登录到一个文件,你需要的API罐子(未 SLF4J-机器人)和 的logback-机器人 。你正在寻找的 FileAppender 或RollingFileAppender.

slf4j-android only supports logging to logcat 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 (not slf4j-android) and logback-android. You're looking for the FileAppender or RollingFileAppender.

添加 SLF4J-API - <版>的.jar 的logback-android-<版>的.jar 到类路径中。

创建文件在你的项目资产/ logback.xml (或使用的Andr​​oidManifest.xml ...查看例如),包含以下配置:

Create the file assets/logback.xml in your project (or use the AndroidManifest.xml...see example), containing the following configuration:

<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 code,其中包含了SLF4J记录来电,现在记录的所有事件达到或超过 DEBUG 级到 / SD卡/testFile.log

Your Java code, which contains the SLF4J logging calls, now logs all events at or above the DEBUG level to the /sdcard/testFile.log.

阅读全文

相关推荐

最新文章