Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Display / System.out.println flow of programs?

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve, will be looking into that, always wondered what that log4j was all about!

Have a good one!
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic