Java tutorial
//package com.java2s; import android.util.Log; public class Main { private static final String TAG = "LOGUTIL"; private static boolean LOG_ENABLE = true; /** * error log * @param msg log msg */ public static void e(String msg) { if (LOG_ENABLE) { Log.e(TAG, buildMsg(msg)); } } /** * error log * @param msg log msg * @param e exception */ public static void e(String msg, Exception e) { if (LOG_ENABLE) { Log.e(TAG, buildMsg(msg), e); } } /** * error log * @param tag tag * @param msg msg */ public static void e(String tag, String msg) { if (LOG_ENABLE) { Log.e(tag, buildMsg(msg)); } } /** * error log * @param tag tag * @param msg log msg * @param e exception */ public static void e(String tag, String msg, Exception e) { if (LOG_ENABLE) { Log.e(tag, buildMsg(msg), e); } } private static String buildMsg(String msg) { StringBuilder buffer = new StringBuilder(); // if (DETAIL_ENABLE) { // final StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4]; // // buffer.append("[ "); // buffer.append(Thread.currentThread().getName()); // buffer.append(": "); // buffer.append(stackTraceElement.getFileName()); // buffer.append(": "); // buffer.append(stackTraceElement.getLineNumber()); // buffer.append(": "); // buffer.append(stackTraceElement.getMethodName()); // } // buffer.append("() ] _____ "); buffer.append(msg); return buffer.toString(); } }