Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CloudWatchLogger

Logger that writes log messages to AWS Cloud Watch Log.

Configuration parameters

  • stream: (optional) Cloud Watch Log stream (default: context name)
  • group: (optional) Cloud Watch Log group (default: context instance ID or hostname)
  • connections:
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • region: (optional) AWS region
  • credentials:
    • store_key: (optional) a key to retrieve the credentials from ICredentialStore
    • access_id: AWS access/client id
    • access_key: AWS access/client id
  • options:
    • interval: interval in milliseconds to save current counters measurements (default: 5 mins)
    • reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)

References

  • *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source
  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connections
  • *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
see

Counter (in the Pip.Services components package)

see

CachedCounters (in the Pip.Services components package)

see

CompositeLogger (in the Pip.Services components package)

Example

let logger = new Logger();
logger.config(ConfigParams.fromTuples(
    "stream", "mystream",
    "group", "mygroup",
    "connection.region", "us-east-1",
    "connection.access_id", "XXXXXXXXXXX",
    "connection.access_key", "XXXXXXXXXXX"
));
logger.setReferences(References.fromTuples(
    new Descriptor("pip-services", "logger", "console", "default", "1.0"),
    new ConsoleLogger()
));

logger.open("123", (err) => {
    ...
});

logger.setLevel(LogLevel.debug);

logger.error("123", ex, "Error occured: %s", ex.message);
logger.debug("123", "Everything is OK.");

Hierarchy

  • CachedLogger
    • CloudWatchLogger

Implements

  • ILogger
  • IReconfigurable
  • IReferenceable
  • IReferenceable
  • IOpenable

Index

Constructors

constructor

Properties

Protected _cache

_cache: LogMessage[]

Protected _interval

_interval: number

Protected _lastDumpTime

_lastDumpTime: number

Protected _level

_level: LogLevel

Protected _maxCacheSize

_maxCacheSize: number

Protected _source

_source: string

Protected _updated

_updated: boolean

Methods

clear

  • clear(): void
  • Removes all [[LogMessage LogMessages]] from this object's cache.

    Returns void

close

  • close(correlationId: string, callback: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

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

    • callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

Protected composeError

  • composeError(error: Error): string
  • Composes an Error string, which can be used in a log entry.

    Parameters

    • error: Error

      the Error to compose a string with.

    Returns string

    the string created using the information from the Error. Example error string: "<error's message> StackTrace: <error's stack>"

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 message using the [[LogLevel.Debug debug]] log level. Calls this class's formatAndWrite method with level set to [[LogLevel.Debug]].

    see

    formatAndWrite

    see

    [[LogLevel]]

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • message: string

      the message to log as debug or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with if it is a format string.

    Returns void

dump

  • dump(): void
  • Dumps the [[LogMessage LogMessages]] that are stored in this object's cache to memory.

    see

    save

    Returns void

error

  • error(correlationId: string, error: Error, message: string, ...args: any[]): void
  • Logs a message using the [[LogLevel.Error error]] log level. Calls this class's formatAndWrite method with level set to [[LogLevel.Error]].

    see

    formatAndWrite

    see

    [[LogLevel]]

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • error: Error

      the Error to include in the log entry.

    • message: string

      the message to log as error or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with if it is a format string.

    Returns void

fatal

  • fatal(correlationId: string, error: Error, message: string, ...args: any[]): void
  • Logs a message using the [[LogLevel.Fatal fatal]] log level. Calls this class's formatAndWrite method with level set to [[LogLevel.Fatal]].

    see

    formatAndWrite

    see

    [[LogLevel]]

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • error: Error

      the Error to include in the log entry.

    • message: string

      the message to log as fatal or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with if it is a format string.

    Returns void

Protected formatAndWrite

  • formatAndWrite(level: LogLevel, correlationId: string, error: Error, message: string, ...args: any[]): void
  • If message is a printf-like format string, then this method formats it using the provided arguments and calls write with the newly formatted string.

    see

    [[LogLevel]]

    see

    write

    Parameters

    • level: LogLevel

      the LogLevel to use.

    • correlationId: string

      unique business transaction id to trace calls across components.

    • error: Error

      the Error to include in the log entry for fatal and error logs.

    • message: string

      the message to log or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with.

    Returns void

getLevel

  • getLevel(): LogLevel
  • Retrieves the [[LogLevel]] that is currently set.

    see

    [[LogLevel]]

    Returns LogLevel

    this logger's LogLevel.

getSource

  • getSource(): string
  • Retrieves the source (context) for which this logger is logging.

    Returns string

    this logger's source (context).

info

  • info(correlationId: string, message: string, ...args: any[]): void
  • Logs a message using the [[LogLevel.Info info]] log level. Calls this class's formatAndWrite method with level set to [[LogLevel.Info]].

    see

    formatAndWrite

    see

    [[LogLevel]]

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • message: string

      the message to log as info or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with if it is a format string.

    Returns void

isOpen

  • isOpen(): boolean
  • Checks if the component is opened.

    Returns boolean

    true if the component has been opened and false otherwise.

log

  • log(level: LogLevel, correlationId: string, error: Error, message: string, ...args: any[]): void
  • Logs a message using the given [[LogLevel]] and parameters. Uses this class's formatAndWrite method.

    see

    formatAndWrite

    Parameters

    • level: LogLevel

      the LogLevel to use.

    • correlationId: string

      unique business transaction id to trace calls across components.

    • error: Error

      the Error to include in the log entry for fatal and error logs.

    • message: string

      the message to log or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with if it is a format string.

    Returns void

open

  • open(correlationId: string, callback: function): void
  • Opens the component.

    Parameters

    • correlationId: string

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

    • callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

Protected 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

  • setLevel(value: LogLevel): void
  • Sets this logger's [[LogLevel]].

    see

    [[LogLevel]]

    Parameters

    • value: LogLevel

      the LogLevel to set this logger to.

    Returns void

setReferences

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

    see

    IReferences (in the Pip.Services commons package)

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

setSource

  • setSource(value: string): void
  • Sets the source (context) for which this logger will be logging.

    Parameters

    • value: string

      the source (context) to set.

    Returns void

trace

  • trace(correlationId: string, message: string, ...args: any[]): void
  • Logs a message using the [[LogLevel.Trace trace]] log level. Calls this class's formatAndWrite method with level set to [[LogLevel.Trace]].

    see

    formatAndWrite

    see

    [[LogLevel]]

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • message: string

      the message to log as trace or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with if it is a format string.

    Returns void

Protected update

  • update(): void
  • Checks whether or not the update interval has passed (since the last dump was performed) and, if it has, performs a dump.

    see

    dump

    Returns void

warn

  • warn(correlationId: string, message: string, ...args: any[]): void
  • Logs a message using the [[LogLevel.Warn warn]] log level. Calls this class's formatAndWrite method with level set to [[LogLevel.Warn]].

    see

    formatAndWrite

    see

    [[LogLevel]]

    Parameters

    • correlationId: string

      unique business transaction id to trace calls across components.

    • message: string

      the message to log as warn or the format string to use for formatting.

    • Rest ...args: any[]

      the arguments to format message with if it is a format string.

    Returns void

Protected write

  • write(level: LogLevel, correlationId: string, ex: 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.

    • ex: Error
    • message: string

      a human-readable message to log.

    Returns void

Generated using TypeDoc