Java JDK Logging Code Sample
The following code sample demonstrates the use of the Java JDK logging facility. This example defines a logger using a logging configuration file and directs the logger to log messages to a file. The program then sends a series of log messages to the logger, which outputs (or publishes) the log messages to the file.
A Formatter instance is then added as a handler. The purpose of this object is to format the output of the logger as a single line of text. (By default, the SimpleFormatter class outputs a head and tail, or two separate lines of text plus the log message for each log message written.)
This sample program creates a logger as a static member of the class in which it will be used. This is the recommended ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access