CompositeLogger

Aggregates all loggers from component references under a single component.

Implements: IReferenceable

Extends: Logger

Description

The CompositeLogger class allows you to aggregate loggers from component references into a single component.

Important points

  • It allows to log messages and conveniently send them to multiple destinations.

References

  • *:logger:*:*:1.0 - (optional) ILogger components to pass log messages

Constructors

Creates a new instance of the logger.

public CompositeLogger(IReferences references) throws ReferenceException

  • references: IReferences - references to locate the component dependencies.

Instance methods

setReferences

Sets references to dependent components.

public void setReferences(IReferences references)

  • references: IReferences - references to locate the component dependencies.

write

Writes a log message to the logger destination.

protected void write(LogLevel level, IContext context, Exception error, String message)

  • level: LogLevel - a log level.
  • context: IContext - (optional) a context to trace execution through call chain.
  • error: Exception - an error object associated with this message.
  • message: String - a human-readable message to log.

Examples

{@code
  class MyComponent implements IConfigurable, IReferenceable {
      CompositeLogger _logger = new CompositeLogger();
 
      public void configure(ConfigParams config) {
         this._logger.configure(config);
         ...
      }
 
      public void setReferences(IReferences references) {
          this._logger.setReferences(references);
          ...
      }
 
      public void myMethod(IContext context) {
          this._logger.debug(context, "Called method mycomponent.mymethod");
          ...
      }
  }
  }

See also