This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
am having many class files in my java project,in which all the methods within the classes have some System.out.println(SOPs)in them. in some cases i need all the SOPs to be printed and in some cases i dont need any of these SOPs to be printed(situation similar to a switch being switched ON/OFF). how can i achieve this?
i can put all SOPs inside if loop havng some condtn but havng IFs for each SOP creates overhead... need a optimised solution....
can i go for overriding SOP?? is tat possible?? [ April 21, 2007: Message edited by: Bear Bibeault ]
Originally posted by sahithya harsha: can i go for overriding SOP??
That would be a very poor approach.
Rather, what you are describing is exactly the purpose of logging. You can use the built-in logging classes in java.util.logging, or popular 3rd-party packages such as Log4J. [ April 21, 2007: Message edited by: Bear Bibeault ]
You can even create your own Logging class, where you can add a flag, which is configurable using a properties file, as to whether or not you wish to print the statements. This is useful because if your application is a small one, using Log4j is not advisable.
You're worried about the performance right? don't be. The moment you compile such a code, a good compiler will remove all the if(Flags.LOGGING) checks. And if you set it to false, and recompile your code, it will remove all the code inside such if blocks including the checks.
but mind you, that's the only hitch- you need to recompile your entire code that uses this class.
"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com