An important tool for Android development is Locat, which is an essential tool for code debugging, error exclusion, etc.
First of all, let me tell you about log.
It belongs to the Android.util.log class. There are 5 common ways to print a log:
:
LOG.V (tag,message);//verbose mode, print the most detailed information
LOG.D (tag,message);//debug mode, print debugging information
LOG.I (tag,message);//info
LOG.W (tag,message);//warning, printing warning information
LOG.E (tag,message);//error, printing error messages
Where tag is the debug information tag name, which is the LOGCAT filter tag,
Message is the information that is printed when debugging,
Output information level error> warn > Info >debug> verbose (available as a reference for filtering information).
All right, so here's the question (^_^)
Every time you want to debug to write a sentence what log.v ("tag", "Debug ...."), and then filter the tag, if an application so many classes will it be annoying to write a word every time? At the same time to apply the release of a sentence to hide the log, more annoying.
So we can consider writing this:
Write a log tool class directly:
public class MyLog {
static Boolean state = true;//If you want to publish the app, you can get rid of the state =false and there will be no log output.
public static void D (String str) {
if (state) {
LOG.I ("N Your App Name:", str);
}
}
}
Then each time you call MYLOG.D (String str) method, and an application in the filter of Logcat write a tag and then your application of the entire log will come out, is not much more convenient, and debug mode when the state is changed to true, There will be a log, when it is published to false all logs will be hidden, will be more convenient.
If it's unclear what kind of log is in an application, there's a better way to do that:
public
class
MyLog {
/**
* 是否开启debug
*/
public
static
boolean
isDebug=
true
;
public
static
void
d(Class<?> clazz,String msg){
if
(isDebug){
Log.e(clazz.getSimpleName(),msg+
""
);
}
}
}
The one above the analogy is more useful, and anyone who has learned Java knows that Clazz.getsimplename () has the function of getting the simplified name of the class. It is also more convenient to distinguish which class of logs is more convenient and clearer.
Well, to here should be over, originally log is very simple things, I here Luo Li said so much, in fact, that is to say that write code we have to be able to save the province, memory can save the province, in the premise of understanding the code can save on the province, to do an environmental protection program ape.
This article is from the "unity of Knowledge" blog, please be sure to keep this source http://poarry.blog.51cto.com/5970996/1570742
The admin tool class log in Android can be .....