让ConsoleHandler输出出现在logcat的输出 [英] Make ConsoleHandler output appear in logcat output

查看:376
本文介绍了让ConsoleHandler输出出现在logcat的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正有做ConsoleHandler的输出出现在logcat中?

Is there anyway to make the output of ConsoleHandler appear in logcat?

我在code以下

ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter (new DMLogFormatter());
consoleHandler.setLevel (Level.ALL);

FileHandler fileHandler = new FileHandler ("logFile", true);
fileHandler.setFormatter (new DMLogFormatter());
fileHandler.setLevel (Level.ALL);

Logger logger = Logger.getLogger ("log");
logger.setUseParentHandlers (false);
logger.setLevel (Level.ALL);
logger.addHandler (fileHandler);
logger.addHandler (consoleHandler);

到的FileHandler输出工作正常。那些对ConsoleHandler不会出现。

The outputs to the FileHandler works fine. Those to the ConsoleHandler does not appear.

我读到在以下查看输出和错误'的的 logcat的文档

I read about the following under 'Viewing stdout and stderr' given in the Logcat documentation

默认情况下,Android系统发送stdout和stderr(System.out和
  System.err的)输出到/ dev / null的。在运行在Dalvik虚拟机,你的进程
  可以让系统写副本输出到日志文件。在这
  情况下,系统使用日志标签标准输出写入的消息到日志
  和标准错误,都与我优先

By default, the Android system sends stdout and stderr (System.out and System.err) output to /dev/null. In processes that run the Dalvik VM, you can have the system write a copy of the output to the log file. In this case, the system writes the messages to the log using the log tags stdout and stderr, both with priority I.

若要在这种方式输出,停止正在运行的模拟器/设备
  实例,然后使用shell命令setprop启用
  输出重定向。这里是你如何做到这一点:

To route the output in this way, you stop a running emulator/device instance and then use the shell command setprop to enable the redirection of output. Here's how you do it:

$亚行外壳停止

$亚行外壳setprop log.redirect-STDIO真正

$ adb shell setprop log.redirect-stdio true

$ ADB shell启动

$ adb shell start

这三个命令没有很好的帮助。是否有可能使ConsoleHandler的输出出现在logcat的输出?

Those three commands did not help as well. Is it possible to make the output of ConsoleHandler appear in Logcat output?

推荐答案

如果你不绑定到 ConsoleHandler ,我建议使用的 SLF4J-的Andr​​oid (其中转储logcat的)或 的logback-的Andr​​oid (其中有目的地几种选择,其中包括<一href=\"http://tony19.github.com/logback-android/doc/1.0.0-4/ch/qos/logback/classic/android/LogcatAppender.html\"相对=nofollow> LogcatAppender )。

If you're not bound to the ConsoleHandler, I recommend using slf4j-android (which dumps to logcat) or logback-android (which has several options for destination, including a LogcatAppender).

这篇关于让ConsoleHandler输出出现在logcat的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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