Interface that allows you to log records. This records are treated by handlers

Constructors

Properties

displayName?: string
key: string

Methods

  • Handle a record

    Use this only if you know what you are doing.

    Type Parameters

    • T extends Metadata

    Parameters

    • record: Readonly<LogRecord<T>>

    Returns void

  • Log an alert message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Create a new Logger with the same key a this attached context

    Parameters

    • context: Record<string, unknown>

    Returns Logger

    const loggerMyService = new Logger('app:myService');
    function someAction(arg1) {
    const logger = loggerMyService.context({ arg1 });
    logger.enter(someAction);
    // do stuff
    logger.info('info');
    // do stuff
    logger.exit(someAction);
    }
  • Log an critical message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log a debug message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log an debug fail message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log an debug success message

    Type Parameters

    • T extends Metadata

    Parameters

    • message: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log an error message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

    const logger = new Logger('something');
    try {
    throw new Error('Always throws here');
    } catch (error) {
    logger.error('caught error', { error });
    }
  • Log an exit in a function

    Type Parameters

    • T extends Metadata
    • Fn extends (...args: unknown[]) => unknown

    Parameters

    Returns void

    const logger = new Logger('myNamespace:A');
    class A {
    method(arg1) {
    // Do your stuff
    logger.exit(method, { arg1 });
    }
    }
  • Alias for infoFail

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log a fatal message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

    const logger = new Logger('something');
    try {
    throw new Error('Always throws here');
    } catch (error) {
    logger.error('caught error', { error });
    process.exit(1);
  • Log an info message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log an info fail message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log an info success message

    Type Parameters

    • T extends Metadata

    Parameters

    • message: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Like timeEnd, but with INFO level

    Type Parameters

    • T extends Metadata

    Parameters

    • time: number
    • message: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Type Parameters

    • T extends Metadata

    Parameters

    • Optionalmessage: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns number

  • Like timeEnd, but with INFO level

    Type Parameters

    • T extends Metadata

    Parameters

    • time: number
    • message: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log an inspected value

    Type Parameters

    • T extends Metadata

    Parameters

    • value: unknown
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log a debugged var

    Type Parameters

    • T extends Metadata

    Parameters

    • varName: string
    • varValue: unknown
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log a message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • level: Level = Level.INFO
    • Optionaloptions: Options<T>

    Returns void

  • Notice an info message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Alias for infoSuccess

    Type Parameters

    • T extends Metadata

    Parameters

    • message: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Type Parameters

    • T extends Metadata

    Parameters

    • Optionalmessage: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>
    • level: number = Level.DEBUG

    Returns number

    time to pass to timeEnd

  • Finds difference between when this method was called and when the respective time method was called, then logs out the difference and deletes the original record

    Type Parameters

    • T extends Metadata

    Parameters

    • startTime: number
    • message: string
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>
    • level: number = Level.DEBUG
    • Optionaloptions: Options<T>

    Returns void

  • Log a trace message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Log a warn message

    Type Parameters

    • T extends Metadata

    Parameters

    • messageOrError: string | Error
    • Optionalmetadata: T
    • OptionalmetadataStyles: MetadataStyles<T>

    Returns void

  • Wrap around a function to log enter and exit of a function

    Type Parameters

    • Fn extends (...args: unknown[]) => unknown

    Parameters

    • fn: Fn
    • callback: () => void

    Returns void

    const logger = new Logger('myNamespace:A');
    class A {
    method() {
    logger.wrap(method, () => {
    // Do your stuff
    });
    }
    }
  • Wrap around a function to log enter and exit of a function

    Type Parameters

    • T extends Metadata
    • Fn extends (...args: unknown[]) => unknown

    Parameters

    • fn: Fn
    • metadata: T
    • callback: () => void

    Returns void

    const logger = new Logger('myNamespace:A');
    class A {
    method() {
    logger.wrap(method, () => {
    // Do your stuff
    });
    }
    }
  • Wrap around a function to log enter and exit of a function

    Type Parameters

    • T extends Metadata
    • Fn extends (...args: unknown[]) => unknown

    Parameters

    • fn: Fn
    • metadata: T
    • metadataStyles: MetadataStyles<T>
    • callback: () => void

    Returns void

    const logger = new Logger('myNamespace:A');
    class A {
    method() {
    logger.wrap(method, () => {
    // Do your stuff
    });
    }
    }