Interpreting the implementation of the android Log Mechanism: (2) Java domain output log

Source: Internet
Author: User

Interpreting the implementation of the android Log Mechanism: (2) Java domain output log

Tian haili @ csdn

 

Android provides a user-level lightweight Log Mechanism. Its implementation runs through Java, JNI, local C/C ++ implementation, Linux kernel driver, and Other Android layers, it is simple and clear enough to explain the case. This seriesArticleThis article explains the internal implementation mechanism of the log mechanism. This article is part two of the series.ProgramHow to output log information to the log system.

 

Log output help class

The android Java program outputs logs through the Android. util. Log class and lists the commonly used static log methods.

Generally, to output log information, you can directly call log. V ()/log. D ()/log. I ()/log. W ()/log. e. There are so many different methods here, which is also the log classification. Log classification is defined as the static constant member of log, and the priority of log is sorted by number. The priority of a large number is higher. While log. what a terrible failure is recorded by WTF (), and this error is reported not only in logs, but also on the interface, the current process may be killed.

If the log priority to be output is lower than the current priority, the log information is not displayed. Generally, before printing logs using the LOG method in Java programs, you should first use isloggable () to determine whether this level can be recorded.

In addition, log. println () can be used to match log. V ()/log. D ()/... And other methods, but when using it, you must specify the corresponding priority.

 

Log-like implementation

The implementation of Android. util. log is relatively simple.

The constructors of the android. util. Log class are private and will not be instantiated. They only provide static attributes and methods.

Android. util. the implementation of various log record methods of log relies on the Implementation of native println_native (), log. V ()/log. D ()/log. I ()/log. W ()/log. E () eventually calls println_native (). For example, the implementation of log. D:

 
Public static int D (string tag, string MSG) {return println_native (log_id_main, debug, Tag, MSG );}

The native method println_native () is implemented in C/C ++ through JNI. For details, see section 3: JNI and C/C ++ in this series.

 

[This series of articles]

Interpreting the implementation of the android Log Mechanism: (1) implementation architecture of log

Interpret the implementation architecture of the log mechanism.

Interpreting the implementation of the android Log Mechanism: (2) Java domain output log

Explain how the android Java program outputs log information to the log system.

Interpreting the implementation of the android Log Mechanism: (3) Writing Device Files in JNI and native Domains

Interpret the JNI Implementation of Android. util. log and how to operate the device file to write log information in the local implementation of C/C ++.

Interpreting the implementation of the android Log Mechanism: (4) Log Device-driven Logger

Interpret the implementation of the device driver logger in the Linux kernel. Logger is a misc Driver written by Android for Linux. It uses cyclic queues to implement readers/writers. Logger is the core of the implementation of the entire log mechanism.

Interpreting the implementation of the android Log Mechanism: (5) Obtaining the log program logcat

Explains how the application logcat obtains log information through open ()/select ()/read () of the device file.

Interpreting the implementation of the android Log Mechanism: (6) using log in the C/C ++ domain

This article explains how to use the Log Mechanism in the C/C ++ program of Android to record log information.

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.