Android normal log output to SD card

Source: Internet
Author: User

This is one of the most responsible people I've ever seen writing a blog:

http://www.crifan.com/android_try_use_android_logging_log4j_to_output_log_to_sd_card_file/

Why do you say he is responsible??

Because the author writes out the whole process from determining the need to finding a solution, it will not only make the reader less detours, but also come clean the solution.

Of course there is some nonsense, the essence of it absorbed, nonsense not to say, on dry:

In Android, the implementation of the output log content in the SD card file, the practice is:

1. Download the log4j library for Android

Go: http://code.google.com/p/android-logging-log4j/

Download the corresponding Android-logging-log4j-1.0.3.jarand add it to the project.

2. Download the dependent Apache log4j Library

Go: http://logging.apache.org/log4j/1.2/download.html

Download the 1.2 series version of: Log4j-1.2.17.zip

Unzip to get Log4j-1.2.17.jar added to the project.

3. Write the Test code:

12345678910111213141516171819202122232425262728 importde.mindpipe.android.logging.log4j.LogConfigurator;importjava.io.File;importandroid.os.Environment;importorg.apache.log4j.Level;importorg.apache.log4j.Logger;public classBaseActivity extendsActivity {    privateLogger gLogger;        publicvoidconfigLog()    {        finalLogConfigurator logConfigurator = newLogConfigurator();                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    protectedvoid onCreate(Bundle savedInstanceState) {        configLog();        gLogger.debug("test android log to file in sd card using log4j");

Can be achieved:

(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

Android normal log output to SD card

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.