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

The main goal of Logahawk is to make it easy to log objects other than strings. To log an object we must somehow convert it into a string, since that's all the underlying logger can understand.

In Logahawk this is primarily accomplished via ArgumentFormatters. These objects interogate the objects you want to log and produce strings that will represent them in the log.

Logahawk comes with many ArgumentFormatters for common objects such as primitives, Files, URLs, lists, maps, etc. You can also urged to create your own ArgumentFormatters for your domain-specific objects. Creating ArgumentFormatters is very easy.

Using ArgumentFormatters Example
Before

For example, this code:

	SimpleLogger logger = new SimpleLogger();
	logger.getListenerContainer().add( new ConsoleListener() ); // output to System.out w/o timestamp
	logger.info( new int[] { 16, 32, 64 } );
      

Outputs:

	  (INFO) Type: [I; ToString: [I@443226
        

Logahawk outputs the "toString()" of the given object when it cannot find an appropriate ArgumentFormatter. Logahawk falls back on the default formatter for objects, which is pretty ugly.

After

See the difference when we add a few formatters!

	SimpleLogger logger = new SimpleLogger();
	logger.getListenerContainer().add( new ConsoleListener() ); // output to System.out w/o timestamp
	logger.getArgumentContainer().add( new ArrayArgFormatter() ); // !!! formats arrays
	logger.getArgumentContainer().add( new PrimitiveArgFormatter() ); // !!! formats primitives (integers)
	logger.info( new int[] { 16, 32, 64 } );
      

Output:

(INFO) (3 items in collection)
    [ 0 ] 16
    [ 1 ] 32
    [ 2 ] 64
      

Much better!