Open Source project Log4android how to use

Source: Internet
Author: User

Words do not say much, directly on the subject.

Log4android is an open-source Android logging project similar to log4j. The project is based on the Microlog adaptation, adding new ways to define the output of the file.

Project Address: Click here (https://github.com/lisicnu/Log4Android)

How to use:

0. Import the package.

The project has been published in the MAVEN repository and can be imported directly into the package, the current version is 1.0.0

Gradle compiled in the following:

Compile ' com.github.lisicnu:log4android:1.0.0 '

1. Initialize the method.

Logmanager.init (context), default to the assets directory to find microlog.properties files to initialize the log.

Logmanager.init (Context,int), opens the specified resource file for initialization and cannot specify an SD card file.

Logmanager.init (Context,int, Boolean), opens the specified file for initialization and can specify the SD card file .

2. Note the point.

Logmanger.isdebug This property determines whether it is a test mode, and if it is a test mode, it is output directly to Logcat, otherwise it is output by profile.

Recommended use method.  Logmanager.isdebug = Buildconfig.debug; This value defaults to true.

3. How to use.

Call LOGMANAGER.V (String, Object). and other methods to log records. Use the same way as the Android.utl.Log method.

4. Configuration files

Complete configuration File Example:


Microlog.formatter=patternformatter
microlog.formatter.patternformatter.pattern=%i%c%d [%P]%m%T
Microlog.appender=fileappender
Microlog.appender.fileappender.file=logs
Microlog.appender.fileappender.options=%a%F-YYYYMMDD
Microlog.level=debug
Microlog.adddefaultlogger=true

Among them, the meaning of Patternformater is as follows

        %i :  // 输出设置的clientId.        %c :  // 输出logger的名称.        %d :  // 输出绝对时间        %m :  // 输出消息        %P :  // 输出等级, 如 DEBUG, WARNING, ERROR 等.        %r :  // 输出从设置之后的相对时间.        %t :  // 输出线程名        %T :  // 输出 throwable的详细信息.        %% :  // 输出 %.

microlog.appender.FileAppender.File 此属性设置文件夹名称, 默认路径为程序外置sd卡数据目录下的logs文件夹.
microlog.appender.FileAppender.Options 设置输出文件的属性.
        %a :  // 追加到日志文件中. 如果没有,则创建新文件.        %f :  // 指定使用日期为文件命名,后可能具体的日期格式. 如 yyyyMMddHHmmss, yyyMMddHHmm等. e.g. %f-yyyyMMddHHmmss        %p :  // 使用固定文件名, 当文件大小达到最大时,默认追加数字索引. 当使用此属性时, microlog.appender.FileAppender.File将被识别为文件名的前缀.        %s :  %s-0.5

Open Source project Log4android how to use

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.