@@ -13,39 +13,53 @@ public final class LogUtils {
1313 private LogUtils () {
1414 }
1515
16- public static void e (Object obj ) {
16+ public static void e (Object message ) {
1717 StackTraceElement element = new Throwable ().getStackTrace ()[1 ];
18+ print (element , message , null );
19+ }
20+ public static void e (Object message , Throwable error ) {
21+ StackTraceElement element = new Throwable ().getStackTrace ()[1 ];
22+ print (element , message , error );
23+ }
24+ private static void print (StackTraceElement element , Object message , Throwable error ) {
1825 String className = element .getClassName ();
1926 className = className .substring (className .lastIndexOf ("." ) + 1 );
2027 String tag = className +'.' +element .getMethodName ()+'(' +element .getFileName ()+':' +element .getLineNumber ()+')' ;
21- String message = toString (obj );
28+ String text = toString (message );
2229
23- Log .e ("[KakaCache]" , tag +"\n \t " +message );
30+ if (error != null ) {
31+ Log .e ("[KakaCache]" , tag + "\n \t " + text , error );
32+ } else {
33+ Log .e ("[KakaCache]" , tag + "\n \t " + text );
34+ }
2435 }
2536
26- private static String toString (Object obj ) {
27- if (obj == null ) {
37+ private static String toString (Object message ) {
38+ if (message == null ) {
2839 return "[null]" ;
2940 }
30- if (obj instanceof Throwable ) {
31- return Log .getStackTraceString ((Throwable ) obj );
41+ if (message instanceof Throwable ) {
42+ return Log .getStackTraceString ((Throwable ) message );
3243 }
33- if (obj instanceof Collection ) {
34- Iterator it = ((Collection ) obj ).iterator ();
44+ if (message instanceof Collection ) {
45+ return toString ((Collection ) message );
46+ }
47+ return String .valueOf (message );
48+ }
49+ private static String toString (Collection message ) {
50+ Iterator it = message .iterator ();
51+ if (! it .hasNext ())
52+ return "[]" ;
53+
54+ StringBuilder sb = new StringBuilder ();
55+ sb .append ('[' );
56+ for (;;) {
57+ Object e = it .next ();
58+ sb .append (e );
3559 if (! it .hasNext ())
36- return "[]" ;
37-
38- StringBuilder sb = new StringBuilder ();
39- sb .append ('[' );
40- for (;;) {
41- Object e = it .next ();
42- sb .append (e );
43- if (! it .hasNext ())
44- return sb .append (']' ).toString ();
45- sb .append (',' ).append ('\n' ).append (' ' );
46- }
60+ return sb .append (']' ).toString ();
61+ sb .append (',' ).append ('\n' ).append (' ' );
4762 }
48- return String .valueOf (obj );
4963 }
5064
5165}
0 commit comments