Make ConsoleHandler output appear in logcat output
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?
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
).
精彩评论