Class Logger

Hierarchy

  • EventEmitter<{
        debug: [data: string];
        entry: [data: string, level: LogLevel];
        error: [data: string | Error];
        info: [data: string];
        notice: [data: string];
        send: [data: IOMessage];
        warn: [data: string | Error];
    }>
    • Logger

Constructors

  • Parameters

    Returns Logger

Properties

_entries: string[] = []
io: Set<IO<SupportedInterface>> = ...
options: Partial<LoggerOptions> = {}
prefixed: string | boolean

Accessors

  • get attachedIO(): number
  • Get the number of attached streams

    Returns number

    number of attached streams

  • get entries(): string[]
  • Gets the array of log entries. Empty if retainLogs is false.

    Returns string[]

    A copy of the log entries array.

Methods

  • Type Parameters

    • T extends "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<{
                debug: [data: string];
                entry: [data: string, level: LogLevel];
                error: [data: string | Error];
                info: [data: string];
                notice: [data: string];
                send: [data: IOMessage];
                warn: [data: string | Error];
            }>[Extract<T, "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry">]

          Returns void

    • Optional context: any

    Returns this

  • Clears retained log entries

    Returns boolean

    whether the entries where cleared or not

  • Logs a debug message with the LogLevel.DEBUG level.

    Parameters

    • Rest ...data: string[]

      The log message.

    Returns void

  • Calls each of the listeners registered for a given event.

    Type Parameters

    • T extends "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Parameters

    • event: T
    • Rest ...args: ArgumentMap<{
          debug: [data: string];
          entry: [data: string, level: LogLevel];
          error: [data: string | Error];
          info: [data: string];
          notice: [data: string];
          send: [data: IOMessage];
          warn: [data: string | Error];
      }>[Extract<T, "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry">]

    Returns boolean

  • Logs an error message with the LogLevel.ERROR level.

    Parameters

    • data: string | Error

      The error or log message.

    Returns Error

    Todo

    Replace with Error.isError once it is widely available

  • Return an array listing the events for which the emitter has registered listeners.

    Returns ("error" | "warn" | "notice" | "info" | "debug" | "send" | "entry")[]

  • Logs a message with the LogLevel.INFO level.

    Parameters

    • Rest ...data: string[]

      The log message.

    Returns void

  • Return the number of listeners listening to a given event.

    Parameters

    • event: "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Returns number

  • Return the listeners registered for a given event.

    Type Parameters

    • T extends "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Parameters

    • event: T

    Returns ((...args) => void)[]

  • Logs a info message with the LogLevel.NOTICE level.

    Parameters

    • Rest ...data: string[]

      The log message.

    Returns void

  • Type Parameters

    • T extends "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<{
                debug: [data: string];
                entry: [data: string, level: LogLevel];
                error: [data: string | Error];
                info: [data: string];
                notice: [data: string];
                send: [data: IOMessage];
                warn: [data: string | Error];
            }>[Extract<T, "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry">]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns this

  • Add a listener for a given event.

    Type Parameters

    • T extends "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<{
                debug: [data: string];
                entry: [data: string, level: LogLevel];
                error: [data: string | Error];
                info: [data: string];
                notice: [data: string];
                send: [data: IOMessage];
                warn: [data: string | Error];
            }>[Extract<T, "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry">]

          Returns void

    • Optional context: any

    Returns this

  • Add a one-time listener for a given event.

    Type Parameters

    • T extends "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Parameters

    • event: T
    • fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<{
                debug: [data: string];
                entry: [data: string, level: LogLevel];
                error: [data: string | Error];
                info: [data: string];
                notice: [data: string];
                send: [data: IOMessage];
                warn: [data: string | Error];
            }>[Extract<T, "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry">]

          Returns void

    • Optional context: any

    Returns this

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Returns this

  • Remove the listeners of a given event.

    Type Parameters

    • T extends "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry"

    Parameters

    • event: T
    • Optional fn: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: ArgumentMap<{
                debug: [data: string];
                entry: [data: string, level: LogLevel];
                error: [data: string | Error];
                info: [data: string];
                notice: [data: string];
                send: [data: IOMessage];
                warn: [data: string | Error];
            }>[Extract<T, "error" | "warn" | "notice" | "info" | "debug" | "send" | "entry">]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns this

  • Outputs a log message to attached outputs.

    Parameters

    • contents: string

      The log message to be sent.

    • level: LogLevel

      The log level for the message. Defaults to LogLevel.LOG.

    Returns void

  • Outputs a log message to attached outputs.

    Parameters

    Returns void

  • Converts the log entries to a string.

    Returns string

    A string representation of the log entries.

  • Logs a warning message with the LogLevel.WARN level.

    Parameters

    • data: string | Error

      The error or log message.

    Returns Error

    Todo

    Replace with Error.isError once it is widely available