简体   繁体   中英

Android log4j Logging Multiple times

Hi Guys got a issue here using Log4j.

My code is

public class MyLogger{
    private static Logger mLogger = LoggerFactory.getLogger(MyLogger.class);

    public static void configure() {
        LogConfigurator logConfigurator = new LogConfigurator();
        logConfigurator.setFileName(getLogPath());
        logConfigurator.setRootLevel(Level.DEBUG);
        logConfigurator.setLevel("com.**", Level.ALL);
        logConfigurator.setMaxFileSize(1024 * 1024 * 5);
        logConfigurator.configure();
    }

    public static void info(String msg) {
        mLogger.info(msg);
    }

    public static void warn(String msg) {
        mLogger.warn(msg);
    }

    public static void debug(String msg) {
        mLogger.debug(msg);
    }

    public static void error(String msg) {
        mLogger.error(msg);
    }

This code works but as I noticed it is logged multiple times. I tried reading some tutorial here and they say that I need to add additivity="false" but that function is not available on Jar file.

Each enabled logging request for a given logger will be forwarded to all the appenders in that logger, as well as the appenders higher in the hierarchy.

Check log4j.properties and make the change to have it set to false :

log4j.additivity.com.javacodegeeks.examples.log4jadditivity.theClass=false

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