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

Implements

  • any
  • any

Index

Constructors

constructor

  • Creates a new instance of this logger.

    Returns CloudWatchLogger

Methods

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

configure

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

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

isOpen

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

    Returns boolean

    true if the component has been opened and false otherwise.

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

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

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