Created
September 11, 2010 02:13
-
-
Save JamesWang/574690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String formatWithStackInfo(String message) { | |
/** | |
* ex.getStackTrace()[0] is this formatWithStackInfo() method ex.getStackTrace()[1] | |
* is your method where you call this method | |
*/ | |
StackTraceElement ste = new Throwable().getStackTrace()[1]; | |
String callerClassName = ste.getClassName(); | |
int callerLineNumber = ste.getLineNumber(); | |
String methodName = ste.getMethodName(); | |
callerClassName = callerClassName.substring(callerClassName | |
.lastIndexOf(".") + 1); | |
return "[" + callerClassName +"." + methodName + ":" + callerLineNumber + "]" + message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment