vendredi 3 juin 2016

Turnoff log4j logger while running unit tests for Android app

I am using log4j to write logs of my android app to sdcard. Unit tests fail while execution as Environment.getExternalStorageDirectory() throws exception. How do I turn off the logger for unit tests ?

I am configuring the logger using following code:

public static Logger getLogger(Class clazz) {
        final LogConfigurator logConfigurator = new LogConfigurator();
        String logsFolderName = Environment.getExternalStorageDirectory().toString() + File.separator + "player/logs/";
        String logFileName = "player.log." + getCurrentDateString();
        logConfigurator.setFileName(logsFolderName + logFileName);
        logConfigurator.setRootLevel(Level.ALL);
        logConfigurator.setLevel("org.apache", Level.ALL);
        logConfigurator.setUseFileAppender(true);
        logConfigurator.setFilePattern("%d %-5p [%c{2}]-[%L] %m%n");
        logConfigurator.setMaxFileSize(1024 * 1024 * 5);
        logConfigurator.setImmediateFlush(true);
        logConfigurator.configure();
        Logger log = Logger.getLogger(clazz);
        return log;
    }

Using the logger within each of my classes using

public static Logger LOGGER = ALogger.getLogger(ObjectState.class)

Aucun commentaire:

Enregistrer un commentaire