import android.util.Log;
public class MyLogUtil {
private static final String TAG = "MyLog";
private static boolean isLogEnabled = true;
public static void v(String msg) {
if (isLogEnabled) {
Log.v(TAG, getLogInfo() + msg);
}
}
public static void d(String msg) {
if (isLogEnabled) {
Log.d(TAG, getLogInfo() + msg);
}
}
public static void i(String msg) {
if (isLogEnabled) {
Log.i(TAG, getLogInfo() + msg);
}
}
public static void w(String msg) {
if (isLogEnabled) {
Log.w(TAG, getLogInfo() + msg);
}
}
public static void e(String msg) {
if (isLogEnabled) {
Log.e(TAG, getLogInfo() + msg);
}
}
private static String getLogInfo() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StackTraceElement targetElement = stackTrace[4];
String className = targetElement.getClassName();
String[] classNameInfo = className.split("\\.");
if (classNameInfo.length > 0) {
className = classNameInfo[classNameInfo.length - 1];
}
String methodName = targetElement.getMethodName();
int lineNumber = targetElement.getLineNumber();
return "[" + className + "." + methodName + ":" + lineNumber + "] ";
}
public static void setLogEnabled(boolean enabled) {
isLogEnabled = enabled;
}
}