File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Display / System.out.println flow of programs? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Display / System.out.println flow of programs?" Watch "Display / System.out.println flow of programs?" New topic
Author

Display / System.out.println flow of programs?

bob connolly
Ranch Hand

Joined: Mar 10, 2004
Posts: 204
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

Joined: May 22, 2003
Posts: 657

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

Joined: Mar 10, 2004
Posts: 204
Thanks Steve, will be looking into that, always wondered what that log4j was all about!

Have a good one!
Julien Grenier
Ranch Hand

Joined: Sep 01, 2005
Posts: 41
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display / System.out.println flow of programs?