Use "Microlog4" for log storage in Android

Source: Internet
Author: User

in the Android project, a log file needs to be put into the SD card for subsequent debugging bugs.

The specific use is as follows:

1. Download the Open source Framework

http://code.google.com/p/microlog4android/downloads/list Download Microlog4android-1.0.0.jar and microlog.properties files



2, establish the use of logger object

private static final Logger Logger = Loggerfactory.getlogger (mainactivity.class);


3. Initialize the method in the OnCreate method of the first activity of the program

Propertyconfigurator.getconfigurator (this). Configure ();


4. Put the microlog.properties file in the Assets folder

Configure the Microlog.properties file for the following:

Microlog.level=debug
Microlog.appender=logcatappender; Fileappender
Microlog.formatter=patternformatter
microlog.formatter.patternformatter.pattern=%c [%P]%m%T


5, write log records for example


Logger.debug ("Show debug level log information only");




6. Add the right to write SD card in Androidmanifest.xml

<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>


run the program, and then to the SD card root directory, you can find that there is a microlog.txt file, inside is our log.


7. How to change the path and name of the log file, you need to configure the parameter "Microlog.appender.FileAppender.File" to change the path and name of the log file.


The configuration file is as follows:

Microlog.level=debug
Microlog.appender=fileappender; Logcatappender
Microlog.appender.fileappender.file=mylog.txt
Microlog.formatter=patternformatter

microlog.formatter.patternformatter.pattern=%c [%P]%m%T


This article is from the "No Water Fish" blog, please be sure to keep this source http://javaqun.blog.51cto.com/10687700/1737221

Use "Microlog4" for log storage in Android

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.