Options
All
  • Public
  • Public/Protected
  • All
Menu

Project @stencila/logga

Index

Functions

addHandler

  • Add a handler.

    Parameters

    • handler: LogHandler

      A function that handles the log data.

    • filter: { func?: (logData: LogData) => boolean; maxLevel?: LogLevel; messageRegex?: RegExp; tags?: string[] } = ...

      Options for filtering log data prior to sending to the handler.

      • Optional func?: (logData: LogData) => boolean

        A function that determines if handler is called

          • Parameters

            Returns boolean

      • Optional maxLevel?: LogLevel

        The maximum log level.

      • Optional messageRegex?: RegExp

        A regex that the log message should match.

      • Optional tags?: string[]

        A list of tags that the log data should match.

    Returns LogHandler

    The handler function that was added.

defaultHandler

  • defaultHandler(data: LogData, options?: { exitOnError?: boolean; fastTime?: boolean; maxLevel?: LogLevel; showStack?: boolean; throttle?: { duration?: number; signature?: string } }): void
  • Default log event handler.

    Prints the event data to stderr:

    • with cutesy emoji, colours and stack (for errors) if stderr is TTY (for human consumption)
    • as JSON if stderr is not TTY (for machine consumption e.g. log files)

    If in Node.js, and the

    Parameters

    • data: LogData

      The log data to handle

    • options: { exitOnError?: boolean; fastTime?: boolean; maxLevel?: LogLevel; showStack?: boolean; throttle?: { duration?: number; signature?: string } } = ...
      • Optional exitOnError?: boolean

        Whether or not to exit the process on the first error. Defaults to true.

      • Optional fastTime?: boolean
      • Optional maxLevel?: LogLevel

        The maximum log level to print. Defaults to info.

      • Optional showStack?: boolean

        Whether or not to show any stack traces for errors. Defaults to false.

      • Optional throttle?: { duration?: number; signature?: string }
        • Optional duration?: number
        • Optional signature?: string

    Returns void

escape

  • escape(value: string): string
  • Escape a string for inclusion in JSON.

    Based on the list at https://www.json.org minus the backspace character (U+0008)

    Parameters

    • value: string

      The string to escape

    Returns string

getLogger

  • getLogger(tag: string): Logger
  • Get a logger for the specific application or package.

    Each of the returned logger functions are the public interface for posting log messages.

    Parameters

    • tag: string

      The unique application or package name

    Returns Logger

handlers

removeHandler

  • Remove a handler.

    Parameters

    • handler: LogHandler

      The handler function to remove.

    Returns void

removeHandlers

  • removeHandlers(): void

replaceHandlers

  • Replace all existing handlers with a new handler.

    This is a convenience function that can be used to replace the default handler with a new one which logs to the console.

    Parameters

    Returns void

Generated using TypeDoc