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