Android easy to manage log log in applications log publish the method of all the log logs are removed _android

Source: Internet
Author: User
Tags log log

There are generally two ways to manage log, and bloggers recommend using the first method below:

The first method:

The first step: Define a Logtools tool class, believe you can understand, whose log, can use whose name do method name, such as Logli, this is engineer Li print log

Copy Code code as follows:

Import Android.util.Log;

public class Logtools {

public static Boolean isshow = true;//Online mode

public static Boolean isshow = false;//Development mode

The log that ye engineers typed out
public static void Logye (String msg) {
if (isshow) {
LOG.I ("Ye", msg);
}
}
The log that the Li engineer typed out
public static void Logli (String msg) {
if (isshow) {
LOG.I ("Lili", MSG);
}
}

}

Step two: The way to apply in a program is:

Copy Code code as follows:

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


The second method:

Log is often printed in development, but cannot be printed when we publish the item. In order to facilitate the operation of log we need to define a log class ourselves and then set the following log_level to 6 in the development phase so that all logs can be displayed, we set the Log_level to 0 when we release it. So the log is very easy to manage.

Copy Code code as follows:

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);
}
}

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.