5.274 Logging

Logging in plugin types uses the Apache Commons Logging and log4j libraries. Each plugin is injected with a method called getLog which can be used to access the configured logger. It returns an instance of org.apache.commons.logging.Log. Examples of using the logger are shown below.

The logger may used to register messages to the MWS log at several levels (in order of severity):

  1. trace
  2. debug
  3. info
  4. warn
  5. error
  6. fatal

Each of these levels is available as a method on the logger, for example:

public void poll() {
	getLog().debug("getLog() is equivalent to just using 'log' in Groovy")
	log.debug("This is a debug message and is used for debugging purposes only")
	log.info("This is a informational message")
	log.warn("This is a warning")
	log.error("This is an error message")
}

Logger name

Each logger in the MWS logging configuration has a name. In the case of plugins, it is comprised of the full class name, including the package, prepended by "plugins.". For example, a plugin class of "example.LoggingPlugin" will have access to a logger configured as plugins.example.LoggingPlugin.

Logging configuration

The logging configuration is done through the MWS configuration file. For more information on configuring loggers, see Configuring Moab Web Services. A good configuration for developing plugin types may be to add "plugins" at the debug level. Be sure to set the log level threshold down for the desired appender.

log4j = {
  …
  // Appender configuration
  ...
  debug "plugins"
}

Related Topics 

© 2016 Adaptive Computing