I've got a method in my class only for testing purpose :
private void printOut(String msg, Object value)
{
System.out.println(msg + value);
}
It is a wrapper method for System.out.println();
So I hope, with the use of Annotation, I can choose not to run this method during productive environment while still keep those diagnostic output ready if I am to switch back to debugging environment.
Which Annotation shall I put on top of the method name?
As I stated above you should use logging. Here are some of the benefits of using logging in an application:
Read more about logging here
There are a lot of logging frameworks in java:
And several facades, which provides abstraction for various logging frameworks:
One solution is to use AspectJ to do this, as you can control the behavior based on annotations.
Here is a tutorial on how to use annotations as join points:
http://www.eclipse.org/aspectj//doc/next/adk15notebook/annotations-pointcuts-and-advice.html
What you could do is to have:
@DebugMessage
private void printOut(String msg, Object value)
{ }
Then, in your aspect you could have the aspect do the println call.
This way, in production, the aspect isn't included, but, should you ever need to have this active, then just add the aspect, even to production code, to get some debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With