Androd encapsulates a Log printing tool for one-click printing without printing

Source: Internet
Author: User

Androd encapsulates a Log printing tool for one-click printing without printing

When writing a project, we cannot avoid using the Log printing tool in Android, but when the code is more and more written, we add a Log and a Log, when our project is going to be launched, we will always forget what logs are there, which is very troublesome. At that time, we had all our hearts and minds. Now we have encapsulated a Log tool, you only need to define a boolean to implement the print and non-print functions with one click. Just copy it and get it to the project!

Don't thank me. Please call me Lei Feng.

Package com. example. qlog; import java. util. calendar; public final class QLog {public static final boolean DEBUG = true; // whether to print/*** Send a {@ link # VERBOSE} log message. ** @ param tag Used to identify the source of a log message. it usually identifies the class or activity where the * log call occurs. * @ param msg The message you wowould like logged. */public static int v (String tag, String format, Ob Ject... args) {if (DEBUG) {if (args = null | args. length = 0) {return android. util. log. v (tag, format);} return android. util. log. v (tag, String. format (format, args);} return 0;}/*** Send a {@ link # DEBUG} log message. ** @ param tag Used to identify the source of a log message. it usually identifies the class or activity where the * log call occurs. * @ param msg The message you wowould like Logged. */public static int d (String tag, String format, Object... args) {if (DEBUG) {if (args = null | args. length = 0) {return android. util. log. d (tag, format);} return android. util. log. d (tag, String. format (format, args);} return 0;}/*** Send an {@ link # INFO} log message. ** @ param tag Used to identify the source of a log message. it usually identifies the class or activity where t He * log call occurs. * @ param msg The message you wowould like logged. */public static int I (String tag, String format, Object... args) {if (DEBUG) {if (args = null | args. length = 0) {return android. util. log. I (tag, format);} return android. util. log. I (tag, String. format (format, args);} return 0;}/*** Send a {@ link # WARN} log message. ** @ param tag Used to identify the source of a log Message. it usually identifies the class or activity where the * log call occurs. * @ param msg The message you wowould like logged. */public static int w (String tag, String format, Object... args) {if (DEBUG) {if (args = null | args. length = 0) {return android. util. log. w (tag, format);} return android. util. log. w (tag, String. format (format, args);} return 0;}/*** Send a {@ link # WARN} log m Essage and log the exception. ** @ param tag Used to identify the source of a log message. it usually identifies the class or activity where the * log call occurs. * @ param tr An exception to log */public static int w (String tag, Throwable tr) {if (DEBUG) {return android. util. log. w (tag, tr);} return 0;}/*** Send an {@ link # ERROR} log message. ** @ param tag Used to identify the source of Log message. it usually identifies the class or activity where the * log call occurs. * @ param msg The message you wowould like logged. */public static int e (String tag, String msg, Throwable e) {if (DEBUG) {return android. util. log. e (tag, msg, e);} return 0;}/*** Send an {@ link # ERROR} log message. ** @ param tag Used to identify the source of a log message. it usually identifies the class or Activity where the * log call occurs. * @ param msg The message you wowould like logged. */public static int e (String tag, String msg) {if (DEBUG) {return android. util. log. e (tag, msg);} return 0;}/*** Low-level logging call. ** @ param priority The priority/type of this log message * @ param tag Used to identify the source of a log message. it usually identifies the class or activity where * Log call occurs. * @ param msg The message you wowould like logged. * @ return The number of bytes written. */public static int println (int priority, String tag, String msg) {if (DEBUG) {return android. util. log. println (priority, tag, msg);} return 0;}/*** print call time ** @ param cur ???? ?? * @ Return call time */public static long debugDuration (long cur) {long sec = System. currentTimeMillis (); StackTraceElement elem = Thread. currentThread (). getStackTrace () [3]; d ("Performance", elem. getFileName () + "_" + elem. getLineNumber () + ":" + (sec-cur); return sec;}/*** print the current call location: file line number method ** @ param tag * @ return */public static int printLogPos (String tag) {StackTraceElement elem = Thread. CurrentThread (). getStackTrace () [3]; return d (tag, elem. getClassName () + ":" + elem. getLineNumber () + ":" + elem. getMethodName ();}/*** get the current call location ?? Class Name ** @ param depth stack depth * @ return */public static String getLogPos (int depth) {StackTraceElement elem = Thread. currentThread (). getStackTrace () [depth]; return elem. getClassName ();}/*** depth = 4 ** @ see # getLogPos (int) * @ return */public static String getLogPos () {return getLogPos (4 );} /*** get the current ?? Code> from???? Seconds ?? ** @ Param from * @ return */public static long getSecond (Calendar from) {return (System. currentTimeMillis ()-from. getTimeInMillis ()/1000;} private static final Calendar _ 20120101 = Calendar. getInstance (); static {_ 20120101.set( 2012, 0, 0, 0, 0);}/*** from = 20120101 ** @ see # getSecond (Calendar) * @ return */public static long getSecond () {return getSecond (_ 20120101 );}}


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.