Android Log Tool Class

Source: Internet
Author: User
Tags date now

Import Java.text.simpledateformat;import Java.util.date;import Android.util.log;public class LogUtil {private static Final Boolean DEBUG = true;public static void D (string tag, string method, String msg) {LOG.D (TAG, "[" + Method + "]" + MS g);} public static void D (string tag, string msg) {if (DEBUG) {log.d (TAG, "[" + Getfilelinemethod () + "]" + msg);}} public static void D (String msg) {if (DEBUG) {log.d (_file_ (), "[" + Getlinemethod () + "]" + msg);}} public static void E (String msg) {if (DEBUG) {LOG.E (_file_ (), Getlinemethod () + msg);}} public static void E (string tag, string msg) {if (DEBUG) {log.e (TAG, Getlinemethod () + msg);}} public static String Getfilelinemethod () {Stacktraceelement traceelement = ((New Exception ()). Getstacktrace ()) [2]; StringBuffer tostringbuffer = new StringBuffer ("["). Append (Traceelement.getfilename ()). Append ("|"). Append (Traceelement.getlinenumber ()). Append ("|"). Append (Traceelement.getmethodname ()). Append ("]"); return tostringbuffer.tostring ();} public static String GEtlinemethod () {Stacktraceelement traceelement = ((New Exception ()). Getstacktrace ()) [2]; StringBuffer tostringbuffer = new StringBuffer ("["). Append (Traceelement.getlinenumber ()). Append ("|"). Append (Traceelement.getmethodname ()). Append ("]"); return tostringbuffer.tostring ();} public static String _file_ () {Stacktraceelement traceelement = ((New Exception ()). Getstacktrace ()) [2];return Traceelement.getfilename ();} public static String _func_ () {Stacktraceelement traceelement = ((New Exception ()). Getstacktrace ()) [1];return Traceelement.getmethodname ();} public static int _line_ () {Stacktraceelement traceelement = ((New Exception ()). Getstacktrace ()) [1];return Traceelement.getlinenumber ();} public static String _time_ () {Date now = new Date (); SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss. SSS "); return Sdf.format (now);}}

  

Android Log Tool Class

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.