• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display / System.out.println flow of programs?

 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Everytime i need to debug a problem i usually put a 'System.out.println(...)' statement at the beginning of each function!

Is there a switch or flag that can be turned on that will print out the function entered as the system flows thru the various programs?

Thanks very much!
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a constant boolean value and some idiom like:

A more robust and extensible solution is to use a logging framework, such as what is available in 1.4 SDK, log4j, etc.

Hope this helps...
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve, will be looking into that, always wondered what that log4j was all about!

Have a good one!
 
Julien Grenier
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If using log4j is too complicated
the cheapest way to do it is to wrap the System.out.println(x) in a static method
like that

public class MySysOut{

public static void print(Object o){
System.out.println(o.toString()); //Comment to line to remove the flow of system.out!
}
}

then instead of calling System.out.println() in your project you just need to call MySysOut.print() , and you can even change the system.out.println call to some writing into a file.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use a vendor framework with an internal standard of writing methodEntry and methodExit log messages in every method. They took "every" a little to literally so that some recursive or commonly used methods show up thousands of times in the log, but otherwise it can be useful to turn them on now & then.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic