- data를 함께 출력하기 귀찮다.
/*
* TraceUtils.java $version 2016. 01. 22.
*
*/
package com.mdiwebma.base.debug;
import android.os.Looper;
import android.util.Log;
/**
* @author djkim
*/
public abstract class TraceUtils {
public static void e(String fmt, Object... args) {
print(5, fmt, args);
}
public static void w(String fmt, Object... args) {
print(3, fmt, args);
}
public static void d(String fmt, Object... args) {
print(2, fmt, args);
}
public static void v(String fmt, Object... args) {
print(1, fmt, args);
}
final static String TAG = "__TRACE__";
private static void print(final int maxLine, String fmt, Object... args) {
StringBuilder sb = new StringBuilder();
sb.append(String.format(fmt, args));
if (maxLine > 2) {
sb.append("\n");
}
int count = 1;
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
String trace = e.toString();
if (!trace.contains("VMStack.getThreadStackTrace")
&& !trace.contains("java.lang.Thread.getStackTrace")
&& !trace.contains(TraceUtils.class.getPackage().getName())) {
sb.append(" at ").append(trace);
sb.append("\n");
count++;
if (count > maxLine) {
break;
}
}
}
switch (maxLine) {
case 5:
Log.e(TAG, sb.toString());
break;
case 3:
Log.w(TAG, sb.toString());
break;
case 2:
Log.d(TAG, sb.toString());
break;
case 1:
Log.v(TAG, sb.toString());
break;
}
}
public static void assertUiThread() {
if (Looper.myLooper() != Looper.getMainLooper()) {
throw new AssertionError("assert Ui Thread");
}
}
}
TraceUtils.v("%s, %d", data, intdata);