jay
jay

Reputation: 2032

Android apk logs in installed devices

I want to store all the runtime info and error logs of my apk within sdcard folder new File(Environment.getExternalStorageDirectory(), /myapk/logs/myapk_date.log). How do I achieve this ?

Extra information - My app will be installed in plug PCs that start on boot, occupy full screen and play certain content sent from the server. This will be the only app any user would see as there would be no user interaction. The apk would upload the logs to the server by EOD.

Upvotes: 0

Views: 344

Answers (1)

Abdullah
Abdullah

Reputation: 965

http://mvnrepository.com/artifact/de.mindpipe.android/android-logging-log4j

Use this jar file

Here is sample code:

public class ALogger {
    public static org.apache.log4j.Logger getLogger(Class clazz) {
        final LogConfigurator logConfigurator = new LogConfigurator();
        logConfigurator.setFileName(Environment.getExternalStorageDirectory().toString() + File.separator + "log/file.log");
        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;
    }
}

In your code, replace the below lines:

PropertyConfigurator.configure(MY_PROP_FILE);
logger = Logger.getLogger( MyClaZZ.class );
With:

logger = ALogger.getLogger(MyClazz.class);

Reference: Using Log4j in android

Upvotes: 1

Related Questions