The Logger API Guide

From Agent Factory

Jump to: navigation, search

Agent Factory includes a simple Java logging mechanism that is implemented through the com.agentfactory.platform.util.Logger class. This logging mechanism is currently the recommended approach to logging information in Agent Factory.

Contents

Log Levels

The class supports four levels of logging:

  • LEVEL_NONE: no logging
  • LEVEL_ERROR: only ERROR level entries
  • LEVEL_WARNING: only entries of level WARNING or higher (i.e. also allows ERROR level messages)
  • LEVEL_DETAIL: display all entries

The logging level can be set either globally (for the whole JVM) or locally to a class.

Logging Methods

The local logging level is set by passing a log level into one of the following five static methods:

  • detail() - adds a DETAIL level entry to the log
  • warning() - adds a WARNING level entry to the log
  • error() - adds an ERROR level entry to the log
  • enter() - adds a WARNING level entry to the log (for use when entry to a method must be logged)
  • exit() - adds a WARNING level entry to the log (for use when exit from a method must be logged)

Each of the above methods takes two arguments as parameters. The first argument is the entry that is to be logged, and the second argument is the class log level.

Class Level Logging

Recommended practice for implementing class level logging to create a CLASS_LOG_LEVEL constant for every class and to set that constant to the required logging level, for example:

 public class LoggedClass {
   private static final int CLASS_LOG_LEVEL = Logger.LEVEL_WARNING;
 
   public static void main(String[] args) {
     Logger.enter("LoggedClass.main() method", CLASS_LOG_LEVEL);
 
     // DO SOMETHING USEFUL
     Logger.detail("[LoggedClass.main] We have done something useful", CLASS_LOG_LEVEL);
 
     Logger.exit("LoggedClass.main() method", CLASS_LOG_LEVEL);
   }
 }

This would result in the following output:

 ENTER: LoggedClass.main() method
 EXIT: LoggedClass.main() method

Global Log Level

Currently, to modify the Global Logging setting, you must modify the Logger.DEFAULT_LEVEL constant.