Created
August 19, 2016 06:46
-
-
Save gooooloo/2dde437504408f79a88f5fa391d0810c to your computer and use it in GitHub Desktop.
get JAVA Line info for log.
This file contains 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
package info.gooooloo; | |
public class MyLineInfo { | |
public static String info() { | |
final StackTraceElement element = new Exception().getStackTrace()[1]; | |
return String.format("%s#%s,%s:%d", | |
element.getClassName(), | |
element.getMethodName(), | |
element.getFileName(), | |
element.getLineNumber()); | |
} | |
static class AAA { | |
public void foo() { | |
System.out.println(MyLineInfo.info()); | |
} | |
} | |
public static void main(String[] args) { | |
System.out.println(MyLineInfo.info()); | |
System.out.println(MyLineInfo.info()); | |
new AAA().foo(); | |
System.out.println(MyLineInfo.info()); | |
System.out.println(MyLineInfo.info()); | |
System.out.println(MyLineInfo.info()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment