log4j support in Android

后端 未结 6 1350
無奈伤痛
無奈伤痛 2020-11-27 04:57

I am attempting to shoehorn an existing SDK onto an android device and one of the dependencies of said SDK is Apache log4j. I am able to load my test program onto the androi

6条回答
  •  心在旅途
    2020-11-27 05:40

    The parser for log4j configuration files is not android safe.slf4j's android compatibility thing with log4j just overrides the log4j classes you will use and forces them to use android logcat style logging. You still don't get the full flexibility of log4j on android. I ported log4j on android in my project https://sourceforge.net/projects/log4j-android/ all you have to do is add the two jars in the binaries directory to you classpath. Then

    static {
        org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
    
        final SocketAppender appender = new SocketAppender("192.168.1.4", 4445);
    
    
        root.addAppender(appender);
    }
    
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(MyClass.class);
    
    static {
        logger.info("Hello logger");
    }
    

    This will start sending out messages to the remote host you specified. You can then see this messages with Chainsaw http://logging.apache.org/log4j/docs/webstart/chainsaw/chainsawWebStart.jnlp. To make chainsaw work click the second check box on the dialog that pops up hit ok, start your app and a new tab should appear. Be aware your firewall might block it...

提交回复
热议问题