Java Reference
In-Depth Information
System.out.println("status is SINGLE");
. . .
}
. . .
}
214
215
However, there is a problem with using System.out.println for trace
messages. When you are done testing the program, you need to remove all print
statements that produce trace messages. If you find another error, however, you
need to stick the print statements back in.
To overcome this problem, you should use the Logger class, which allows you to
turn off the trace messages without removing them from the program.
Instead of printing directly to System . out, use the global logger object
Logger.global and call
Logger.global.info("status is SINGLE");
By default, the message is printed. But if you call
Logging messages can be deactivated when testing is complete.
Logger.global.setLevel(Level.OFF);
at the beginning of the main method of your program, all log message printing is
suppressed. Thus, you can turn off the log messages when your program works
fine, and you can turn them back on if you find another error. In other words, using
Logger.global.info is just like System.out.println , except that you
can easily activate and deactivate the logging.
A common trick for tracing execution flow is to produce log messages when a
method is called, and when it returns. At the beginning of a method, print out the
parameters:
public TaxReturn(double anIncome, int aStatus)
{
Logger.global.info("Parameters: anIncome = "
+ anIncome
+ " aStatus = " + aStatus);
. . .
}
Search WWH ::




Custom Search