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 ...

Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.