Hierarchy

Constructors

Properties

inner: Logger
name: string
uniqueMessages: Set<string> = ...

Methods

  • Parameters

    • name: string | symbol
    • args: any[]
    • returnValue: any

    Returns any

  • Parameters

    • name: string | symbol
    • args: any[]

    Returns void

  • Parameters

    • name: string | symbol
    • args: any[]
    • error: any

    Returns any

  • Write a log entry to the log, this will be filtered by the log level and optional filters that are set.

    Messages are formatted using the following rules:

    • If a single argument is passed it will be used as the message
    • If a single argument is passed and it is an error it will be used as the message and the stack trace will be appended
    • If a single argument is passed and it is an object it will be serialized to JSON
    • If a single argument is passed and it is a function it will be executed and the result will be used as the message
    • If multiple arguments are passed the first argument will be used as a format string and the remaining arguments will be used as format arguments
    • If a format string is used it can contain the following format specifiers:
      • %s String
      • %i Integer (no decimals)
      • %d Decimal with 2 decimals
      • %d:<X> Decimal with X decimals
      • %S String in uppercase
      • %<any other character> The character will be ignored

    Parameters

    • level: LogLevel

      Log level of the entry to write

    • Rest ...args: any[]

      Arguments to write to the log entr. If a single argument is passed it will be used as the message, otherwise the first argument will be used as a format string and the remaining arguments will be used as format arguments

    Returns void

    Example

    logger.write(LogLevel.info, 'Hello', 'world'); // Hello world this is great
    logger.write(LogLevel.info, 'Hello %s', 'world'); // Hello world
    logger.write(LogLevel.info, 'Hello %S', 'world'); // Hello WORLD
    logger.write(LogLevel.info, 'Hello %d', 1.234); // Hello 1.23
    logger.write(LogLevel.info, 'Hello %d:3', 1.234); // Hello 1.234
    logger.write(LogLevel.info, 'Hello %i', 1.234); // Hello 1
    logger.write(LogLevel.info, 'Hello %i', 1234); // Hello 1234
    logger.write(LogLevel.info, 'Hello %s', { foo: 'bar' }); // Hello {"foo":"bar"}
    logger.write(LogLevel.info, 'Hello %s', () => 'world'); // Hello world
    logger.write(LogLevel.info, 'Hello %s', 'world', 'this', 'is', 'great'); // Hello world this is great
    logger.write(LogLevel.info, 'Hello', 'world %s %s %s', 'this', 'is', 'great'); // Hello world this is great