mercoledì 11 aprile 2012

Android - log4j iteraction.




The best reference to better understand the correct iteraction with the most common used logging library is the google code wiki page.

http://code.google.com/p/android-logging-log4j/.

The first problem I found is the answer to the question:" where the hell, I have to put my log4j.xml " 

It seems no log4j.xml needed, but the configuration has to be somthing like that :

import org.apache.log4j.Level;
import android.os.Environment;
import de.mindpipe.android.logging.log4j.LogConfigurator;
/**
 * Simply place a class like this in your Android applications classpath.
 */
public class ConfigureLog4J {
    static {
        final LogConfigurator logConfigurator = new LogConfigurator();
                
        logConfigurator.setFileName(Environment.getExternalStorageDirectory() + "myapp.log");
        logConfigurator.setRootLevel(Level.DEBUG);
        // Set log level of a specific logger
        logConfigurator.setLevel("org.apache", Level.ERROR);
        logConfigurator.configure();
    }
}


Nessun commento:

Posta un commento