Is there a way in Java to dynamically get the current line number through reflection or some awesome API? Just like when exceptions occur, the line number gets printed out in the stack trace like this:
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348)
Now is there a way to print or log like in the below code?
log.error("Error in: " + this.getClass.getName() + "at line #"+ this.getClass.getActualLine());
You may ask, why don't I simply print the line number? Well because the code may get deleted or added before the specific log.error() method call.