O'Reilly logo

J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software by Art Taylor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required