The SingleLineFormatter Class

The SimpleFormatter class in the JDK logging package uses three lines of text to produce a log entry. The previous example demonstrated the use of a custom log output formatter. To produce a more concise log output message, the SingleLineFormatter class we develop here is used to format a message that uses only a single line of text. Attaching a formatter to a Handler object requires an object which implements the Formatter abstract class. For convenience, we choose to extend the SimpleFormatter class, which provides a concrete implementation of the Formatter abstract class, and we extend only the methods whose behavior we wish to alter. The code for this class is shown below.

We first create a class declaration, ...

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.