简体   繁体   中英

How to add a sockethandler to logcat on a 2013 nexus 7 with android 6.0.1?

doing something naive like:

SocketHandler socketHandler=new SocketHandler(host,service);
socketHandler.setLevel(Level.ALL);
Logger global=Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
global.addHandler(socketHandler);

does not seems to work.

edit: global.severe("foo") does work. but the rest of the logcat messages do not appear.

i would like all (or most) of the logcat messages to go to the log server.

I think you also need LogRecord , see example below:

    Logger logger = Logger.getLogger("concrete.log");

    Handler handle = new SocketHandler("localhost", 8080);

    LogRecord logRec = new LogRecord(Level.INFO, "Log will be recorded");

    handle.publish(logRec);

    handle.setFormatter(new XMLFormatter());

    logger.addHandler(handle);

    logger.info("socket handler info message");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM