Easy Management of log printing information in Android apps

Source: Internet
Author: User

We are debuggingProgramWhen the program is released, it is always necessary to print various log information. Some people use the system out method to print the log information, which is easy to understand, it is not allowed to print to the console. On the contrary, if the printed information is in the virus and anti-virus fields, it may leave a chance for the bad guys.

When developing, we need to select the log printing method. Is there a proper way to manage logs? During development, I printed it out. When I published it, I turned off all the logs?

The answer is yes, so let the author give you one by one:

There are two methods to manage logs. We recommend that you use the following method:

Method 1:

Step 1: Define a logtools tool class. I believe you can understand who's log, whose name can be used as the method name, such as logli. This is the log printed by engineer Li.

 Import  Android. util. log; Public   Class  Logtools {  Public   Static   Boolean Isshow = True  ; // Launch mode

// Public Static BooleanIsshow =False; // Development Mode

// Ye EngineerOutput log Public Static Void Logye (string MSG ){ If (Isshow) {log. I ( "Ye" , MSG );}}// Logs written by Li engineers Public Static Void Logli (string MSG ){ If (Isshow) {log. I ( "Lili" , MSG );}}}

Step 2: the application method in the program is:

Logtools. logye ("ontouchevent -----" + event. getaction ());

Method 2:

Log is often printed during development, but cannot be printed during project release. To facilitate log operations, we need to define a log class and set the following log_level to 6 in the development phase so that all logs can be displayed. At the time of release, we set the log_level to 0. this makes log management very convenient.

 Public   Class  Logger {  Public   Static   Int Log_level = 0 ;  Public  Static   Int Error = 1 ;  Public   Static   Int Warn = 2 ;  Public   Static   Int Info = 3 ;  Public   Static   Int DEBUG = 4 ;  Public  Static   Int Verbos = 5 ;  Public   Static   Void  E (string tag, string MSG ){  If (Log_level> Error) log. E (TAG, MSG );}  Public   Static   Void  W (string tag, string MSG ){  If (Log_level>Warn) log. W (TAG, MSG );}  Public   Static   Void  I (string tag, string MSG ){  If (Log_level> Info) log. I (TAG, MSG );}  Public   Static   Void  D (string tag, string MSG ){  If (Log_level> Debug) log. D (TAG, MSG );}  Public  Static   Void  V (string tag, string MSG ){  If (Log_level> Verbos) log. V (TAG, MSG );}} 

 

Okay, let's get started. Come on, friend!

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.