Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CachedLogger

Abstract logger that caches captured log messages in memory and periodically dumps them. Child classes implement saving cached messages to their specified destinations.

Configuration parameters

  • level: maximum log level to capture
  • source: source (context) name
  • options:
    • interval: interval in milliseconds to save log messages (default: 10 seconds)
    • max_cache_size: maximum number of messages stored in this cache (default: 100)

References

  • *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source
see

ILogger

see

Logger

see

LogMessage

Hierarchy

Implements

Index

Constructors

constructor

Properties

Protected _cache

_cache: LogMessage[] = []

Protected _interval

_interval: number = 10000

Protected _lastDumpTime

_lastDumpTime: number = new Date().getTime()

Protected _level

_level: LogLevel = LogLevel.Info

Protected _maxCacheSize

_maxCacheSize: number = 100

Protected _source

_source: string = null

Protected _updated

_updated: boolean = false

Methods

clear

  • clear(): void
  • Clears (removes) all cached log messages.

    Returns void

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

dump

  • dump(): void
  • Dumps (writes) the currently cached log messages.

    see

    write

    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

Protected Abstract save

  • save(messages: LogMessage[], callback: function): void
  • Saves log messages from the cache.

    Parameters

    • messages: LogMessage[]

      a list with log messages

    • callback: function

      callback function that receives error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    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

Protected update

  • update(): void
  • Makes message cache as updated and dumps it when timeout expires.

    see

    dump

    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.

    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