In-depth analysis of the Android JDK log framework

Source: Internet
Author: User

A large number of mobile phone users around the world have never used any log framework based on Android JDK. Google's goal is to make it independent of devices or even platforms. I hope you can help us after reading this article.

Log records are important for software maintenance, especially for software debugging after being deployed to the running environment. In actual projects, it is often necessary to provide more complex log functions than the framework. The JDK log framework has sufficient scalability to customize log processing, message formatting, log message level, and other components for different requirements.

In the following content, this article describes how to extend the Android JDK log framework and customize log processing methods. This section describes how to use the Log Service of Android JDK and STAFSoftware Testing Automation Framework as an automated Testing Framework to monitor Java programs.

  • Precautions for building the Android platform
  • How can I purchase an Android mobile phone?
  • Full parsing of the Android operating system
  • Understanding Android open-source systems in a short time
  • Learn about the notes of the Android mobile operating system

The log framework of JDK is the java. util. logging package. For a software log system, you must first have a log object that Records log information. At the same time, this information can be output to different locations, such as the console, files, and even networks. The information format can be output to common text, XML, or HTML based on different requirements.

At the same time, different levels of log information need to be classified. The advantage is that redundant information can be filtered and only key logs are retained. For a log framework. The log object must be configurable. It can be output to the specified destination according to the configuration. At the same time, it can determine the output format and the log level or above to be output.

Configuration can also be in a variety of forms, both code form and configuration file form. Especially in the form of configuration files, for a software deployed in the running environment, it is very convenient to change the log configuration without changing its source code.

The log framework provides all the above functions. It mainly includes the following components:

Logger: log record object. Used to record log information. Handler: used to process the output of log information. In the Handler class, you can decide whether the log is output to the file or the console. Filter: used to Filter logs. In the Filter class, you can determine whether to output the Log Based on the log level or certain conditions. In this way, redundant information is removed.

Formatter: used to format log information. This class can format the log text into XML or HTML format, which fully depends on the specific implementation. Level: indicates the log Level. The Android JDK log framework has the following levels by default: SEVERE, WARNING, INFO, CONFIG, FINE, FINER, and FINEST.

For a program, its Logger object will first determine whether the log level meets the output level requirements, and then deliver the log messages meeting the level requirements to the configured Handler object for processing, if a Filter object is configured for the log object. The Filter object filters the log information once. After the Handler object receives the log message, it changes the log format according to its configured Formatter class.

The log information is filtered again based on the configured Filter object and Level object, and finally output to the output location specified by the Handler object. The output location can be console or file, network socket or even memory buffer. Its Architecture Model

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.