This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

a tough nut to crack

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"gudiya",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Njoy!!
Sid
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is useful because if your application is a small one, using Log4j is not advisable.


I can't understand why. I find it useful in any application. Can you please explain ?
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I won't spend time on debating the advantages or disadvantages of logging.
one might also advocate the use of AOP for this purpose- but that is beyond the point.

Gudiya,
the answer is simple.
Have a class like this

class Flags{

public static final boolean LOGGING=true;

}

and use it in your code

...
if(Flags.LOGGING){
System.out.println(...);
}
...

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.
 
Destroy anything that stands in your way. Except this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!