/** * tell you where in the code you are, class/method/line * * @param depth Set to 1 if you call youAreHere directly. * Set to 2 if you call it indirectly via a piece of code that * does something with the String it generates, and you * really want the location of its caller. */ public static String youAreHere( int depth ) { final Throwable t = new Throwable(); final StackTraceElement[] es = t.getStackTrace(); final StackTraceElement e = es[ depth ]; return "at " + e.getClassName() + "." + e.getMethodName() + " line:" + e.getLineNumber(); }