Java Reference
In-Depth Information
will result in the following output on the screen:
11/12/2004 19:39:27 Test main
SEVERE: My program did something bad
and the following output in the temp.log file:
11/12/2004 19:39:27 Test main
SEVERE: My program did something bad
If you wanted to have some other form of output, consider making your own formatter.
The source code to SimpleFormatter is available in the JDK sources, and is only 80 lines for the
entire formatter—it would be easy to create your own formatter.
You will have noticed that logging has so far been going to the screen, even though we
have not asked for this. This is because by default each logger will use its parent's log handlers
in combination with its own. The default anonymous logger will, by default, send output to
the screen. That is, if you get a logger for example.com , and another logger for example.com.
test , the logger for example.com.test is a child of example.com . So any message logged to the
example.com.test logger will also be sent to the handler for example.com . You can turn this
behavior off by calling the setUseParentHandlers(boolean useParentHandlers) method on
the child logger.
You should not remove logging code before deploying in production. Doing so runs the
risk that you may remove something you didn't intend to remove, and if you later need the
logging back again, you will have to add it all again manually. It is a much better idea to use
the logger's rotating log scheme to ensure that log files never get too large, in combination
with setting the log level so that you are not producing too many log messages—usually
either the Level.WARNING or Level.SEVERE log level. You would normally also turn off any log-
ging to the screen (if you have not already done so).
Summary
Spending a little bit of time up front in planning your project can pay big dividends in reduc-
ing total time spent on this assignment. Ensuring that your code is easy to read and maintain
will win you better marks in this assignment, as well as more respect from your colleagues at
work. And using the tools provided by Sun can make your submission far more professional.
We have introduced some of the features that will help you make a more professional
submission, and assist you in your day-to-day life.
FAQs
Q Is it necessary to follow the methodologies and standards in this chapter?
A There are requirements in your instructions that you must follow, and using Javadoc is
one such requirement. However, the use of methodologies and standards is not always
fully stipulated—if you do not have a specific requirement, you can ignore the stan-
dard, but you do so at your own risk.
Search WWH ::




Custom Search