Java tutorial
//package com.java2s; import android.util.Log; public class Main { private static final boolean DEBUG = true; public static void e(String msg) { if (DEBUG) { Log.e(_FILE_(), getLineMethod() + msg); } } public static void e(String TAG, String msg) { if (DEBUG) { Log.e(TAG, getLineMethod() + msg); } } public static String _FILE_() { StackTraceElement traceElement = ((new Exception()).getStackTrace())[2]; return traceElement.getFileName(); } public static String getLineMethod() { StackTraceElement traceElement = ((new Exception()).getStackTrace())[2]; StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getLineNumber()).append(" | ") .append(traceElement.getMethodName()).append("]"); return toStringBuffer.toString(); } }