用于登录到文件Android的最佳记录 [英] Android best logger for logging into file

查看:246
本文介绍了用于登录到文件Android的最佳记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的记录器框架,这在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登录到一个文件,你需要的<一个href="http://search.maven.org/remotecontent?filepath=org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar">API罐子(未 SLF4J-机器人)和 的logback-机器人 。你正在寻找的 FileAppender 或<一个href="http://logback.qos.ch/manual/appenders.html#RollingFileAppender"><$c$c>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.

  1. 添加 SLF4J-API - &LT;版&GT;的.jar 的logback-android-&LT;版&GT;的.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,确保使用<一个href="http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE"><$c$c>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.

这篇关于用于登录到文件Android的最佳记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆