Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Logger

Hierarchy

  • EventEmitter
  • EventEmitter
    • Logger

Indexable

[key: string]: any

Index

Constructors

constructor

  • Representation of a logging subject.

    Parameters

    • Default value name: string = "root"

      The name of the logging subject.

    • Default value options: LoggerOptions = {}

      Options to apply to instance.

    Returns Logger

  • Representation of a logging subject.

    Parameters

    • Optional name: string

      The name of the logging subject.

    • Optional options: LoggerOptions

      Options to apply to instance.

    Returns Logger

Properties

Protected children

children: Logger[] = []

Child Logger instances.

listeners

listeners: EventListener[] = []

name

name: string

The name of a logging subject that the instance represents.

template

template: string = null

The template to be used when parsing LoggerEntry.data for an LoggerEntry.message. When a log message is not defined, the data associated with it can be used to create the message.

For example:

const logger = require('nomatic-logging');
logger.template = '{method} {url} ==> {status} {length} bytes';
logger.log('info', {
 method: 'GET',
 url: '/api/v1/users?page=1',
 status: 200,
 length: 1203
};

The LoggerEntry (sent on execute of each associated transport) would include a message property set toGET /api/v1/users?page=1 ==> 200 1203 bytes.

When defining a template, variables from the log LoggerEntry's data object are used. The name of the variable should be contained within curly braces, i.e. '{key}' would be replaced with value if data has a property of key with value of value.

By default, a template is not used, so a message must be specified when calling log (or a method associated with a log level). If template is defined, a message is optional, and template will not be used if a message is defined.

Protected transports

transports: Transport[] = []

Transport instances which are triggered in the log method (or a method associated with a log level).

type

{Array}

Accessors

levels

  • Return the log levels available and their associated priority.

    Returns LoggerLevels

  • Set the levels available for this instance. When levels are set, methods are created for new levels, while levels not specified on assignment are deleted.

    Parameters

    Returns void

maxListeners

  • get maxListeners(): number
  • set maxListeners(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

Methods

configure

  • configure(options: LoggerOptions): void
  • configure(options: LoggerOptions): void
  • Configure the instance at or after instantiation. All child instances will also be configured with the options specified.

    Parameters

    Returns void

  • Parameters

    • options: LoggerOptions

    Returns void

create

  • create(name: string, options?: LoggerOptions): Logger
  • create(name: string, options?: LoggerOptions): Logger
  • Create a child Logger instance.

    Parameters

    Returns Logger

  • Parameters

    • name: string
    • Optional options: LoggerOptions

    Returns Logger

emit

  • emit(namespace: string, ...data: any[]): void
  • Parameters

    • namespace: string
    • Rest ...data: any[]

    Returns void

find

  • find(name: string): Logger
  • find(name: string): Logger
  • Parameters

    • name: string

    Returns Logger

  • Parameters

    • name: string

    Returns Logger

get

  • get(name: string): Logger
  • get(name: string): Logger
  • Find or create a child instance. If child instance has not already been created, options is inherited from this instance.

    Parameters

    • name: string

    Returns Logger

  • Parameters

    • name: string

    Returns Logger

log

  • log(level: string, messageOrData: string | Object, data?: Object): void
  • log(level: string, messageOrData: string | Object, data?: Object): void
  • Parse, validate, and pass a log entry to all associated transports.

    Parameters

    • level: string
    • messageOrData: string | Object
    • Optional data: Object

    Returns void

  • Parameters

    • level: string
    • messageOrData: string | Object
    • Optional data: Object

    Returns void

on

  • on(namespace: string | RegExp, callback: Function, once?: boolean): EventListener
  • Subscribe a callable function to a namespace.

    Parameters

    • namespace: string | RegExp
    • callback: Function
    • Default value once: boolean = false

    Returns EventListener

    Used to manage the subscription status via open and close methods.

once

  • once(namespace: string | RegExp, callback: Function): EventListener
  • Subscribe a callable function to a namespace, for exactly one execution.

    Parameters

    • namespace: string | RegExp
    • callback: Function

    Returns EventListener

    Used to manage the subscription status via open and close methods.

pop

  • pop(listener: EventListener): boolean
  • Remove a Listener instance from the EventNamespace instance. Called with unsubscribe method.

    Parameters

    • listener: EventListener

    Returns boolean

    A true value indicates a successful pop.

push

  • push(listener: EventListener): void
  • Add a Listener instance to the EventNamespace instance. Called with subscribe method.

    Parameters

    • listener: EventListener

    Returns void

register

  • register(logger: Logger): boolean
  • register(logger: Logger): boolean
  • Register a child instance.

    Parameters

    Returns boolean

    : If false, child is already registered, else returns true.

  • Parameters

    • logger: Logger

    Returns boolean

use

  • Associate a transport to the instance. Transports are executed from log method.

    Parameters

    Returns void

  • Parameters

    Returns void