[Java] view plaincopyprint?
For development work on the android platform, some Log output debugging information is often used.
As we all know, there are five types of android Log, v, d, I, w, e here will not be described (if you do not know these friends, we recommend reading android_Tutor blog http://www.bkjia.com/kf/201205/132161.html, the above is very detailed)
This article describes how to control Log output and shutdown in a unified manner.
Generally, log is output in the debug version, and log output is disabled in the release version. How is this done? Let's look at the code below.
Create a new class file Log. java in your current project. This class file is placed in the current Working Package (you can also create a separate package to store this class file)
In the following class file, we repackage the original 10 log functions in android. Defines a constant DEBUG and outputs Log information only when DEBUG is true.
[Java] package com. android. gallery3d. util;
Public class Log {
Private static final boolean DEBUG = true;
Public static void v (String tag, String msg ){
If (DEBUG ){
Android. util. Log. v (tag, msg );
}
}
Public static void v (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. v (tag, msg, tr );
}
}
Public static void d (String tag, String msg ){
If (DEBUG ){
Android. util. Log. d (tag, msg );
}
}
Public static void d (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. d (tag, msg, tr );
}
}
Public static void I (String tag, String msg ){
If (DEBUG ){
Android. util. Log. I (tag, msg );
}
}
Public static void I (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. I (tag, msg, tr );
}
}
Public static void w (String tag, String msg ){
If (DEBUG ){
Android. util. Log. w (tag, msg );
}
}
Public static void w (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. w (tag, msg, tr );
}
}
Public static void w (String tag, Throwable tr ){
If (DEBUG ){
Android. util. Log. w (tag, tr );
}
}
Public static void e (String tag, String msg ){
If (DEBUG ){
Android. util. Log. e (tag, msg );
}
}
Public static void e (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. e (tag, msg, tr );
}
}
}
Package com. android. gallery3d. util;
Public class Log {
Private static final boolean DEBUG = true;
Public static void v (String tag, String msg ){
If (DEBUG ){
Android. util. Log. v (tag, msg );
}
}
Public static void v (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. v (tag, msg, tr );
}
}
Public static void d (String tag, String msg ){
If (DEBUG ){
Android. util. Log. d (tag, msg );
}
}
Public static void d (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. d (tag, msg, tr );
}
}
Public static void I (String tag, String msg ){
If (DEBUG ){
Android. util. Log. I (tag, msg );
}
}
Public static void I (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. I (tag, msg, tr );
}
}
Public static void w (String tag, String msg ){
If (DEBUG ){
Android. util. Log. w (tag, msg );
}
}
Public static void w (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. w (tag, msg, tr );
}
}
Public static void w (String tag, Throwable tr ){
If (DEBUG ){
Android. util. Log. w (tag, tr );
}
}
Public static void e (String tag, String msg ){
If (DEBUG ){
Android. util. Log. e (tag, msg );
}
}
Public static void e (String tag, String msg, Throwable tr ){
If (DEBUG ){
Android. util. Log. e (tag, msg, tr );
}
}
}
In the current package, Log. v, Log. I, Log. w, Log. e, and Log. d can be used to Log.
It is also easy to Log in other packages, as long as the class name can be imported. The preceding class file is used as an example to import com. android. gallery3d. util. Log in the class file of other packages;
You can use the original Log function to create a Log.
Set DEBUG to false in the software version of Release to disable Log output.
From fulinwsuafcie's column