Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CompositeLogger

Aggregates all loggers from component references under a single component.

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

References

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

ILogger

Example

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(string correlationId): void {
        this._logger.debug(correlationId, "Called method mycomponent.mymethod");
        ...
    }
}

Hierarchy

Implements

Index

Constructors

constructor

  • Creates a new instance of the logger.

    Parameters

    • Default value references: IReferences = null

      references to locate the component dependencies.

    Returns CompositeLogger

Properties

Protected _level

_level: LogLevel = LogLevel.Info

Protected _source

_source: string = null

Methods

Protected composeError

  • composeError(error: Error): string
  • Composes an human-readable error description

    Parameters

    • error: Error

      an error to format.

    Returns string

    a human-reable error description.

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

debug

  • debug(correlationId: string, message: string, ...args: any[]): void
  • Logs a high-level debug information for troubleshooting.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

error

  • error(correlationId: string, error: Error, message: string, ...args: any[]): void
  • Logs recoverable application error.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • error: Error

      an error object associated with this message.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

fatal

  • fatal(correlationId: string, error: Error, message: string, ...args: any[]): void
  • Logs fatal (unrecoverable) message that caused the process to crash.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • error: Error

      an error object associated with this message.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

Protected formatAndWrite

  • formatAndWrite(level: LogLevel, correlationId: string, error: Error, message: string, ...args: any[]): void
  • Formats the log message and writes it to the logger destination.

    Parameters

    • level: LogLevel

      a log level.

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • error: Error

      an error object associated with this message.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

getLevel

  • Gets the maximum log level. Messages with higher log level are filtered out.

    Returns LogLevel

    the maximum log level.

getSource

  • getSource(): string
  • Gets the source (context) name.

    Returns string

    the source (context) name.

info

  • info(correlationId: string, message: string, ...args: any[]): void
  • Logs an important information message

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

log

  • log(level: LogLevel, correlationId: string, error: Error, message: string, ...args: any[]): void
  • Logs a message at specified log level.

    Parameters

    • level: LogLevel

      a log level.

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • error: Error

      an error object associated with this message.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

setLevel

  • Set the maximum log level.

    Parameters

    • value: LogLevel

      a new maximum log level.

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

setSource

  • setSource(value: string): void
  • Sets the source (context) name.

    Parameters

    • value: string

      a new source (context) name.

    Returns void

trace

  • trace(correlationId: string, message: string, ...args: any[]): void
  • Logs a low-level debug information for troubleshooting.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

warn

  • warn(correlationId: string, message: string, ...args: any[]): void
  • Logs a warning that may or may not have a negative impact.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • message: string

      a human-readable message to log.

    • Rest ...args: any[]

      arguments to parameterize the message.

    Returns void

Protected write

  • write(level: LogLevel, correlationId: string, error: Error, message: string): void
  • Writes a log message to the logger destination(s).

    Parameters

    • level: LogLevel

      a log level.

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • error: Error

      an error object associated with this message.

    • message: string

      a human-readable message to log.

    Returns void

Generated using TypeDoc