Logahawk Logo
Logahawk
Logging should be easy - Easy to code and easy to read
MessageFormatter

The MessageFormatter is the last formatter used in constructing a log message. This formatter pieces together the LogMeta (which contains the Severity and a timestamp), and text constructed from the others formatters into a string which is passed to the underlying logger framework. (See integration for more details on the underlying logger framework.)

This formatter is intended to be used by Listeners implementations. Using this formatter is completely optional. Most of the Listeners used by Logahawk use a MessageFormatter bcause it reduces the implementation effort.

Example
Before

For example, this code:

SimpleLogger logger = new SimpleLogger();
logger.getListenerContainer().add( new ConsoleListener() ); // output to System.out w/o timestamp
logger.getArgumentContainer().add( new StringArgFormatter() );
logger.info( "a typical log message" );
      

Outputs:

(INFO) a typical log message
      

Using a SimpleMessageFormatter. (The SimpleMessageFormatter is the default for ConsoleListener because pure console applications tend to have short life spans.)

After

Watch what happens when we change the MessageFormatter to more recognizable StandardMessageFormatter.

SimpleLogger logger = new SimpleLogger();
logger.getListenerContainer().add( new ConsoleListener( new StandardMessageFormatter() ) ); // output to the console
logger.getArgumentContainer().add( new StringArgFormatter() );
logger.info( "a typical log message" );
      

Output:

2009-12-26T20:53:03.687Z INFO : a typical log message
        

The date is now prepended, as we would expect in most logging applications.

This example seems rather uninteresting, but there are some. The next release of Logahawk contains some more interesting MessageFormatter implementations.