Interpreting the implementation of the Android LOG Mechanism: (2) JAVA domain output LOG

Source: Internet
Author: User

 

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 series of articles explains the internal implementation mechanism of the LOG mechanism. This article is the second of this series. It explains how the Android Java program outputs 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.

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.