In Android, the implementation of the output log content in the SD card file, the practice is:
1. Importer of two jar packages
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/79/FC/wKioL1agQQGjIHylAAAOrxTQSxs168.png "title=" 1.png " alt= "Wkiol1agqqgjihylaaaorxtqsxs168.png"/>
2. Test code
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 baseactivity extends activity { private logger glogger; public void configlog () { final LogConfigurator Logconfigurator = new logconfigurator (); logconfigurator.setfilename ( Environment.getexternalstoragedirectory () + File.separator + "Crifanli_log4j.log"); // Set the root log level logconfigurator.setrootlevel (level.debug); // set log level of a specific Logger logconfigurator.setlevel ("Org.apache", Level.ERROR) ; logconfigurator.configure (); //glogger = logger.getlogger (This.getclass ()); glogger = logger.getlogger ("Crifanlilog4jtest"); } @Override protected void OnCreate (bundle savedinstancestate) { configlog (); glogger.debug ("Test android log to file in sd card using log4j "); }
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>&NBSP;
Otherwise it will be reported caused by:java.io.FileNotFoundException:/storage/sdcard0/crifanli_log4j.log:open failed:eacces ( Permission denied) error
Finally, you can implement
(1) The corresponding Crifanli_log4j.log file can be generated in the/mnt/sdcard
(2) The contents of the log output are debug and correspond to their own string identifiers Crifanlilog4jtest
Jar Package http://down.51cto.com/data/2155282
This article from "No Water Fish" blog, reproduced please contact the author!
Using log4j in Android