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!