Skip to content

Instantly share code, notes, and snippets.

@fredgrott
Created January 24, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredgrott/1672197 to your computer and use it in GitHub Desktop.
Save fredgrott/1672197 to your computer and use it in GitHub Desktop.
new way to log
package com.github.shareme.loga;
import org.apache.log4j.Level;
import de.mindpipe.android.logging.log4j.LogConfigurator;
import android.os.Environment;
import android.util.Config;
/**
* Two calls to use:
*
* ConfigLog4j.setOurAPPLog("ourAppLogFIlenamestring");
* ConfigLog4j configLog4j = new ConfigLog4j();
*
* ourAppLogFilenamestring should be say the application main package name
* for example.
*
*
* @author fredgrott
*
*/
public class ConfigLog4j {
String ourAppLog;
/**
* We configure the the android-logging-log4j here in the constructor
* making sure to set for logcat if debugging app by developer and
* to set it to file appender logger if not in debug mode.
*/
public ConfigLog4j() {
if (Config.DEBUG) {
final LogConfigurator logConfigurator = new LogConfigurator();
logConfigurator.setUseLogCatAppender(true);
logConfigurator.setLogCatPattern("m%n%");
logConfigurator.setRootLevel(Level.DEBUG);
// Set log level of a specific logger
logConfigurator.setLevel("org.apache", Level.ERROR);
logConfigurator.configure();
}else {
final LogConfigurator logConfigurator = new LogConfigurator();
logConfigurator.setFileName(Environment.getExternalStorageDirectory() + ourAppLog);
logConfigurator.setRootLevel(Level.DEBUG);
// Set log level of a specific logger
logConfigurator.setLevel("org.apache", Level.ERROR);
logConfigurator.configure();
}
}
public void setOurAppLog(String ourAppLog) {
this.ourAppLog = ourAppLog;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment