Java Reference
In-Depth Information
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
FINER: finer detailed message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
FINE: fine detailed message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
CONFIG: configuration message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
INFO: informational message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
WARNING: warning message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
SEVERE: severe message
The contents of the config log file look like this:
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample recalculate
INFO: fundAmount = 11000.0
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample recalculate
INFO: fundAmount = 11000.0
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample recalculate
INFO: fundAmount = 11000.0
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample recalculate
INFO: fundAmount = 11000.0
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample recalculate
INFO: fundAmount = 11000.0
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample recalculate
INFO: fundAmount = 11000.0
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
SEVERE: monthlyPension is too low.
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
CONFIG: configuration message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
INFO: informational message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
WARNING: warning message
Aug 12, 2014 5:54:43 PM chapter6.LoggerExample main
SEVERE: severe message
Naturally, there are many more messages in the finer log file, because it includes more levels
(particularly, the entering and exiting messages, which are defined as finer level messages). Also,
note that neither log contains the “finest detailed message” from the main method. This is too
low level for the finer logger to log. You can see again here that the fundAmount is 11000 every
time the method is called, again suggesting that the value is not being stored and used in future
calculations. But you can see for sure that the method is being entered and exited as expected.
This leads to the same conclusion (and fix) as before, but logging allows ongoing monitoring of
live applications. Simply by increasing the level of the logger, you can control how many and what
types of messages are logged.
So far, you've only seen the built‐in logger, but Log4j is a popular alternative logger. The Log4j
utility has been in use for 15 years, but Apache Log4j 2 was released in 2014. It offers high perfor-
mance, flexibility, and usability, and is well worth your consideration when deciding on a logging
utility. You can download Log4j 2 at http://logging.apache.org/log4j/2.x/index.html .
Search WWH ::




Custom Search