Logahawk Logo
Logahawk
Logging should be easy - Easy to code and easy to read
Usage
Architecture
overview

There are four main parts to Logahawk's architecture:

  1. Logger - Used by program code (developers) to create log statements
  2. SignatureFormatters - Modifies the list of objects specified by the log statement
  3. ArgumentFormatters - Converts objects into Strings to be logged
  4. MessageFormatters - Creates the final String to be logged

The other two parts of the diagram

  1. Program - Your program
  2. Logging Framework - The library that actually handles the details of logging (e.g. log4j. See Integration for more details
Create Logger

The first step is to create a Logger. The most basic but complete Logger implementation is the SimpleLogger. It has everything most users will need. (You can also implement your own Logger to suit your needs.)

	Logger logger = new SimpleLogger();
      

If you wish to find Loggers from a static registry (which some applications prefer), you can create your Loggers and register them with a LoggerRegistry. (Currently all setup must be done manually. Logahawk does not use configuration files. While not as convienient, this allows the flexibility of creating Loggers dynamically.)

Add Listeners

The most important step is to add one or more Listeners to the Logger you just created. The SimpleLogger provides methods to add Listeners.

Outpus to System.out

	SimpleLogger logger = new SimpleLogger();
	logger.getListenerContainer().add( new ConsoleListener() ); // !!!
      

The most common Listener type is one that sends Logahawk formatted messages to some underlying logging framework. See the integration page for more details on choosing an underlying logger framework.

Outpus to logj4

	SimpleLogger logger = new SimpleLogger();
	logger.getListenerContainer().add( new Log4jListener() ); // !!!
      
Add Formatters

Just as important as adding Listeners is adding Formatters. Without formatters Logahawk will produce rather ugly (and less useful) log messages. The SimpleLogger also provides methods to directly add formatters.

	SimpleLogger logger = new SimpleLogger();
	logger.getListenerContainer().add( new ConsoleListener() );
	Utils.addStandardFormatters( logger ); // !!!
      

The Util library class can be used to add all of the formatters that come with Logahawk. (There are a few formatters that are not added by default because they are incompatible with the standard formatters.)

	SimpleLogger logger = new SimpleLogger();
	logger.getListenerContainer().add( new ConsoleListener() );
	logger.getArgumentContainer().add( new StringArgFormatter() ); // formats strings
	logger.getArgumentContainer().add( new ArrayArgFormatter() ); // formats arrays
	logger.getArgumentContainer().add( new PrimitiveArgFormatter() ); // formats primitives
      

I highly recommend building some formatters that are specific to your application.

Finished

You're all done! Happy logging!