EPLog.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package epson.print.Util;
  2. import android.util.Log;
  3. import epson.print.CommonDefine;
  4. public final class EPLog {
  5. public static final String TAG = "Epson App";
  6. private static boolean isDebug = false;
  7. public static final void heap(String str) {
  8. }
  9. private static String null2str(String str) {
  10. return str == null ? "(null)" : str;
  11. }
  12. private EPLog() {
  13. }
  14. public static void setDebuggable(boolean z) {
  15. if (z) {
  16. isDebug = true;
  17. } else {
  18. isDebug = false;
  19. }
  20. }
  21. public static void v() {
  22. if (isDebug) {
  23. Log.v("Epson App", getMetaInfo());
  24. }
  25. }
  26. public static void v(String str) {
  27. if (isDebug) {
  28. Log.v("Epson App", getMetaInfo() + null2str(str));
  29. }
  30. }
  31. public static void v(String str, String str2) {
  32. if (isDebug) {
  33. Log.v(str, getMetaInfo() + null2str(str2));
  34. }
  35. }
  36. public static void d() {
  37. if (isDebug) {
  38. Log.d("Epson App", getMetaInfo());
  39. }
  40. }
  41. public static void d(String str) {
  42. if (isDebug) {
  43. Log.d("Epson App", getMetaInfo() + null2str(str));
  44. }
  45. }
  46. public static void d(String str, String str2) {
  47. if (isDebug) {
  48. Log.d(str, getMetaInfo() + null2str(str2));
  49. }
  50. }
  51. public static void i() {
  52. if (isDebug) {
  53. Log.i("Epson App", getMetaInfo());
  54. }
  55. }
  56. public static void i(String str) {
  57. if (isDebug) {
  58. Log.i("Epson App", getMetaInfo() + null2str(str));
  59. }
  60. }
  61. public static void i(String str, String str2) {
  62. if (isDebug) {
  63. Log.i(str, getMetaInfo() + null2str(str2));
  64. }
  65. }
  66. public static void w(String str) {
  67. if (isDebug) {
  68. Log.w("Epson App", getMetaInfo() + null2str(str));
  69. }
  70. }
  71. public static void w(String str, String str2) {
  72. if (isDebug) {
  73. Log.w(str, getMetaInfo() + null2str(str2));
  74. }
  75. }
  76. public static void w(String str, Throwable th) {
  77. if (isDebug) {
  78. Log.w("Epson App", getMetaInfo() + null2str(str), th);
  79. printThrowable(th);
  80. if (th.getCause() != null) {
  81. printThrowable(th.getCause());
  82. }
  83. }
  84. }
  85. public static void w(String str, String str2, Throwable th) {
  86. if (isDebug) {
  87. Log.w(str, getMetaInfo() + null2str(str2), th);
  88. printThrowable(str, th);
  89. if (th.getCause() != null) {
  90. printThrowable(th.getCause());
  91. }
  92. }
  93. }
  94. public static void e(String str) {
  95. if (isDebug) {
  96. Log.e("Epson App", getMetaInfo() + null2str(str));
  97. }
  98. }
  99. public static void e(String str, String str2) {
  100. if (isDebug) {
  101. Log.e(str, getMetaInfo() + null2str(str2));
  102. }
  103. }
  104. public static void e(String str, Throwable th) {
  105. if (isDebug) {
  106. Log.e("Epson App", getMetaInfo() + null2str(str), th);
  107. printThrowable(th);
  108. if (th.getCause() != null) {
  109. printThrowable(th.getCause());
  110. }
  111. }
  112. }
  113. public static void e(String str, String str2, Throwable th) {
  114. if (isDebug) {
  115. Log.e(str, getMetaInfo() + null2str(str2), th);
  116. printThrowable(str, th);
  117. if (th.getCause() != null) {
  118. printThrowable(th.getCause());
  119. }
  120. }
  121. }
  122. public static void e(Throwable th) {
  123. if (isDebug) {
  124. printThrowable(th);
  125. if (th.getCause() != null) {
  126. printThrowable(th.getCause());
  127. }
  128. }
  129. }
  130. private static void printThrowable(Throwable th) {
  131. Log.e("Epson App", th.getClass().getName() + ": " + th.getMessage());
  132. for (StackTraceElement stackTraceElement : th.getStackTrace()) {
  133. Log.e("Epson App", " at " + getMetaInfo(stackTraceElement));
  134. }
  135. }
  136. private static void printThrowable(String str, Throwable th) {
  137. Log.e(str, th.getClass().getName() + ": " + th.getMessage());
  138. for (StackTraceElement stackTraceElement : th.getStackTrace()) {
  139. Log.e("Epson App", " at " + getMetaInfo(stackTraceElement));
  140. }
  141. }
  142. private static String getMetaInfo() {
  143. return getMetaInfo(Thread.currentThread().getStackTrace()[4]);
  144. }
  145. public static String getMetaInfo(StackTraceElement stackTraceElement) {
  146. StringBuffer stringBuffer = new StringBuffer();
  147. String className = stackTraceElement.getClassName();
  148. String substring = className.substring(className.lastIndexOf(CommonDefine.DOT) + 1);
  149. String methodName = stackTraceElement.getMethodName();
  150. int lineNumber = stackTraceElement.getLineNumber();
  151. stringBuffer.append("[");
  152. stringBuffer.append(substring);
  153. stringBuffer.append("#");
  154. stringBuffer.append(methodName);
  155. stringBuffer.append(":");
  156. stringBuffer.append(lineNumber);
  157. stringBuffer.append("]");
  158. return new String(stringBuffer);
  159. }
  160. public static final void heap() {
  161. heap("Epson App");
  162. }
  163. }