Package de.uni_trier.wi2.procake.utils.logger

CAKE Logger and Eventhandler

CAKE contains a log system that is similar to the Log4J system. Even more, in the default configuration Log4J is used as logging backend. The characteristics of the CAKE log system are:

  • support for several Levels of importance: debug, information, warning, error, fatal
  • possibility to distinguish which CAKE component creates the log messages
  • possibility to add other components as listener to the log system to get informed about events (Logger.addLoggerListener(LoggerListener)
  • log messages are not included in the code and can be easely replaced with other languages
  • the logging backend can be easely replaced, e.g., by database logger or network loggers

To log a message several information is necessary:

  • the name of the component that wants to log
  • the log message or the key of the log message
  • the classloader of the object that wants to log
  • several parameters for the log messages

Log Component and Log Key

To identify each component and each key it is important that the component-key pair is unique. This is realised with special interfaces that are located in each package that want to log. These interfaces are always named LogComponentIdentifer.

Interface LogComponentIdentifier

This interface is located in each package that want to log and always contains the following information:

  • The name of the component, stored in the constant COMPONENT
  • For each class that logs a message the interface provides a constant with a prefix for the log key. This prefix must be used by a class to create unique keys, in general, the the prefix is appended by two further digits.

Log Messages

It can be confusing that the log message is not located in the java files. But the logger uses the component, key, caller, and parameters to translate each log message by using the de.uni_trier.wi2.procake.utils.multilanguage package. A detailed description how this is done is located there.

In some situations it is necessary to store the log message in the java byte code. This can be simple realised by using the log message as key. The key can be a simple string containing patterns to format the parameters. A detailed description and examples of the patterns can be found in MessageFormatter.