1.首先去下载Android log4j库 http://code.google.com/p/android-logging-log4j/
下载
2.再去下载apache log4j库http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip
3.下载后两个jar包导入项目
如图:
4.编写 测试代码
import de.mindpipe.android.logging.log4j.LogConfigurator;
import java.io.File;
import android.os.Environment;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class Log4jUtil {
private static Logger gLogger;
public static void configLog(String msg) {
final LogConfigurator logConfigurator = new LogConfigurator();
logConfigurator.setFileName(Environment.getExternalStorageDirectory()
+ File.separator + "crifanli_log4j.log");
// Set the root log level
logConfigurator.setRootLevel(Level.INFO);
// Set log level of a specific logger
logConfigurator.setLevel("org.apache", Level.INFO);
logConfigurator.configure();
// gLogger = Logger.getLogger(this.getClass());
gLogger = Logger.getLogger("CrifanLiLog4jTest");
gLogger.info(msg);
}
}
6.结果