The admin tool class log in Android can be .....

Source: Internet
Author: User

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 .....

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.