Make ConsoleHandler output appear in logcat output

岁酱吖の 提交于 2019-12-12 04:31:42

问题


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

I have the following in the 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);

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

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

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.

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:

$ adb shell stop

$ adb shell setprop log.redirect-stdio true

$ adb shell start

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


回答1:


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).



来源:https://stackoverflow.com/questions/6606366/make-consolehandler-output-appear-in-logcat-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!