Using log4j in Android

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.