Address: http://marspring.mobi/android-log/
Android logs differ from those of Java EE such as log4j. For example, you cannot simply set the log to be printed by level, or print the information of the class that calls the log in the log, method Name, row number, and so on. Stacktraceelement is used to encapsulate the android log class. You can print the class in which the current log is located, the method name called, and the row number.
/*****/Package COM. XX. market. util; import Java. util. collection; import Java. util. hashmap; import Java. util. iterator; import Java. util. set; import android. util. log; public class logutility {public static Boolean getdecideresult (stacktraceelement Ele) {return true;} public static string getcallerinfo () {stacktraceelement [] stack = (New throwable ()). getstacktrace (); stacktraceelement ele = NULL; string classname = ""; string methodname = ""; int lineno = 0; If (stack. length> 2) {ele = stack [2]; try {classname = Class. forname (Ele. getclassname ()). getsimplename (); methodname = ELE. getmethodname (); lineno = ELE. getlinenumber ();} catch (classnotfoundexception e) {}} string callerinfo = classname + ":" + methodname + ":" + lineno + "=>"; return callerinfo ;} public static void I (string tag, double info) {If (constants. debug) {log. I (TAG, getcallerinfo () + String. valueof (Info) ;}} public static void I (string tag, float info) {If (constants. debug) {log. I (TAG, getcallerinfo () + String. valueof (Info) ;}} public static void I (string tag, int info) {If (constants. debug) {log. I (TAG, getcallerinfo () + String. valueof (Info) ;}} public static void I (string tag, long info) {If (constants. debug) {log. I (TAG, getcallerinfo () + String. valueof (Info) ;}} public static void I (string tag, string info) {If (constants. debug) {log. I (TAG, getcallerinfo () + String. valueof (Info) ;}} public static void W (string tag, string info) {If (constants. warn) {log. W (TAG, getcallerinfo () + info) ;}} public static void E (string tag, string info) {If (constants. error) {log. E (TAG, getcallerinfo () + info) ;}@ suppresswarnings ("rawtypes") public static void I (string tag, string startmsg, collection info) {If (constants. debug) {stringbuffer MSG = NULL; If (startmsg = NULL) {MSG = new stringbuffer (getcallerinfo ();} else {MSG = new stringbuffer (getcallerinfo () + startmsg);} iterator itr = info. iterator (); While (itr. hasnext () {MSG. append (itr. next (). tostring (); MSG. append (";");} log. I (TAG, MSG. tostring () ;}@ suppresswarnings ("rawtypes") public static void I (string tag, string startmsg, hashmap info) {If (constants. debug) {stringbuffer MSG = NULL; If (startmsg = NULL) {MSG = new stringbuffer (getcallerinfo ();} else {MSG = new stringbuffer (getcallerinfo () + startmsg);} set keyset = info. keyset (); iterator itr = keyset. iterator (); While (itr. hasnext () {object key = itr. next (); object value = info. get (key); MSG. append (key. tostring (); MSG. append ("="); MSG. append (value. tostring (); MSG. append (";");} log. I (TAG, MSG. tostring () ;}} public static void debugforimage (string info) {// remove if (constants. debug) {log. I ("market-Lion", getcallerinfo () + info) ;}} public static void debug (string info) {// remove if (constants. debug) {log. I ("list", getcallerinfo () + info );}}}