Java tutorial
//package com.java2s; import android.text.TextUtils; import android.util.Log; public class Main { public static final int VERBOSE = 1; public static final int LEVEL = VERBOSE; public static final String SEPARATOR = ","; public static void v(String message) { if (LEVEL <= VERBOSE) { StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3]; String tag = getDefaultTag(stackTraceElement); Log.v(tag, getLogInfo(stackTraceElement) + message); } } public static void v(String tag, String message) { if (LEVEL <= VERBOSE) { StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3]; if (TextUtils.isEmpty(tag)) { tag = getDefaultTag(stackTraceElement); } Log.v(tag, getLogInfo(stackTraceElement) + message); } } public static String getDefaultTag(StackTraceElement stackTraceElement) { String fileName = stackTraceElement.getFileName(); String stringArray[] = fileName.split("\\."); String tag = stringArray[0]; return tag; } public static String getLogInfo(StackTraceElement stackTraceElement) { StringBuilder logInfoStringBuilder = new StringBuilder(); String threadName = Thread.currentThread().getName(); long threadID = Thread.currentThread().getId(); String fileName = stackTraceElement.getFileName(); String className = stackTraceElement.getClassName(); String methodName = stackTraceElement.getMethodName(); int lineNumber = stackTraceElement.getLineNumber(); logInfoStringBuilder.append("[ "); logInfoStringBuilder.append("threadID=" + threadID).append(SEPARATOR); logInfoStringBuilder.append("threadName=" + threadName).append(SEPARATOR); logInfoStringBuilder.append("fileName=" + fileName).append(SEPARATOR); logInfoStringBuilder.append("className=" + className).append(SEPARATOR); logInfoStringBuilder.append("methodName=" + methodName).append(SEPARATOR); logInfoStringBuilder.append("lineNumber=" + lineNumber); logInfoStringBuilder.append(" ] "); return logInfoStringBuilder.toString(); } }