Created
January 24, 2012 19:56
-
-
Save fredgrott/1672197 to your computer and use it in GitHub Desktop.
new way to log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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