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 constructor(references: IReferences = null)

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

Instance methods

setReferences

Sets references to dependent components.

public setReferences(references: IReferences): void

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

write

Writes a log message to the logger destination.

protected write(level: LogLevel, context: IContext, error: Error, message: string): void

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

Examples

class MyComponent implements IConfigurable, IReferenceable {
    private _logger: CompositeLogger = new CompositeLogger();

    public configure(config: ConfigParams): void {
        this._logger.configure(config);
        ...
    }

    public setReferences(references: IReferences): void {
        this._logger.setReferences(references);
        ...
    }

    public myMethod(context: Context): void {
        this._logger.debug(context, "Called method mycomponent.mymethod");
        ...
    }
}

See also