使用哪个Android日志记录框架? [英] Which Android logging framework to use?

查看:1040
本文介绍了使用哪个Android日志记录框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题似乎很容易回答,但是有几个好的解决方案. 我喜欢选择最好的".

My question seems to be easily answerable, but there are several good solutions. I like to choose the 'best' one.

  • Androlog
  • SLF4J Android
  • Log4J - Android
  • Pro:类似于Android日志记录框架,因此对现有代码仅进行了很小的更改;能够在错误报告(有关异常的日志)中发送更详细的崩溃报告;漂亮的日志
  • 缺点:没有标准的java"getLogger"方法;通过将属性文件上传到sdcard可以实现生产配置;我需要手动调用初始化日志.需要创建像常量这样的LOG_TAG,或者通过Aspect修改它来创建日志标记常量,以实现标准行为:标记是类名;当日志记录是一项业务需求时,我们需要对其进行测试.在Android上测试静态调用几乎是不可能的;记录器不能由框架注入
  • Pro:登录Java的标准方式;与SLF4J兼容;能够解析属性文件;
  • 缺点:没有内置的崩溃报告系统;在我看来:它不常用,所以使用它可能会很危险;
  • Pro:似乎是由更多人开发的,例如Log4J-Android;如果关闭记录器,logger.debug("Some log message. Details: {}", someObject.toString());是跳过字符串连接的好方法.委派给android.util.Log的轻量级记录器绑定.
  • Con:由于Android平台上日志标签的长度限制(例如,将com.example.myapp.MyClass标签转换为c*.e*.m*.MyClass),自动生成的日志标签长度为< = 23个字符不同类别的标签(例如,com.example.app.MyClasscom.example.anotherapp.MyClass都转换为c*.e*.a*.MyClass);没有内置的崩溃报告系统.
  • Pro: Seems to be developed by more people like Log4J-Android; The logger.debug("Some log message. Details: {}", someObject.toString()); is a good, and effective way to skip string concatenations if the logger is turned off; lightweight logger binding that delegates to android.util.Log.
  • Con: Auto generated log tags that are <= 23 characters long due to a length restriction of log tags on the Android platform (e.g., com.example.myapp.MyClass tag translated to c*.e*.m*.MyClass), which can result in the same log tag for different classes (e.g., com.example.app.MyClass and com.example.anotherapp.MyClass both translate to c*.e*.a*.MyClass); No built in crash reporting system.

除了这些,我喜欢Androlog的行为,但是我是Java开发人员,熟悉log4j/slf4j. 我们肯定会需要崩溃报告系统,但是有几个崩溃报告框架(除了android默认崩溃报告).

Besides of these, I like Androlog behavior, but I'm a Java dev, familiar with log4j/slf4j. We will definitely need crash report system, but there are several frameworks for crash reporting (beside of android default crash report).

我可以将其中一些结合起来,例如使用Log4J android,但是创建一个附加器以使用androlog框架,但是迟早会很混乱,应该避免.

I can combine some of them, for example use Log4J android, but create an appender to use the androlog framework, but sooner or later it will be a mess, which should be avoided.

感谢您的建议,我希望结果将有助于将来决定其他人.

Thanks for your suggestions, I hope the results will help decide others in the future.

如下所述,我可以结合使用:log4j-android和slf4j(如果我将使用log4j,我更喜欢这样做,因为日志格式支持("{}",...)),但它不能回答问题.我必须选择一个框架,然后才能用SLF4J门面装饰它.

As mentioned below, I can combine for ex: log4j-android with slf4j (whitch I prefer to do if I'll use log4j, because the log formatting support ("{}",...) ), but it does not answers the question. I have to choose a framework, then I can decorate it with the SLF4J facade.

推荐答案

更好的方法.我认为是使用SLF4J API及其一些实现.

The better way. I think, is to use SLF4J API + some of its implementation.

对于Android应用程序,您可以使用以下内容:

For Android applications you can use the following:

  1. Android Logger 是轻量级但易于配置的SLF4J实现(<50 Kb).
  2. LOGBack 是最强大且最优化的实现,但其大小约为1 Mb.
  3. 您喜欢的其他任何人: slf4jandroid slf4j-android .
  1. Android Logger is the lightweight but easy-to-configure SLF4J implementation (< 50 Kb).
  2. LOGBack is the most powerful and optimized implementation but its size is about 1 Mb.
  3. Any other by your taste: slf4jandroid, slf4j-android.

这篇关于使用哪个Android日志记录框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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