Reputation: 10168
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?
Upvotes: 2
Views: 2990
Reputation: 5363
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:
Upvotes: 11
Reputation: 262824
You should really follow uthark's advice and use a logging framework.
Those have been specifically designed for this situation.
Doing something "funky" will probably cause problems later on.
Upvotes: 3
Reputation: 41848
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.
Upvotes: 8