Variable logConst

log: {
    _level: number;
    debug: ((...values) => void);
    error: ((...values) => void);
    getLevel: (() => number);
    info: ((...values) => void);
    setLevel: ((level) => void);
    success: ((...values) => void);
    trace: ((...values) => void);
    warn: ((...values) => void);
} = ...

Logger provides a way to annotate code to provide logging, but also allows logging to be turned off (or down) depending on requirements.

The Log Level (detail of logging reported) is taken from command line argument eg.

--loglevel warn

or can be selected in code with log.setLevel()

Example:

import {log} from 'libs-js';

log.warn('Something not quite going to plan');
log.success('Completed', 'sorting');

Using logger in your code:

Place log messages at the appropriate level throughout your code. If they don't log anything, they will run very quickly.

import {log} from '@ortac/libs-js';

log.warn('file failed to download');
log.success('task completed');
const i = 5;
log.debug('i:', i);

Assuming your application is started with a logging level of 'warn' or 2, the following will be output from the above code:

  0:00:00.071  file failed to download

Whereas if your application is started with a logging level of 'debug' or 5:

  0:00:00.071  file failed to download
  0:00:00.074  task completed
  0:00:00.074  i: 5

Initialising log level on the command line

When you start your code, the command line setting will determine the logging level. If none is set on the command line the default is 2 (warn) if in a 'production' environment, or 3 (info/success) if not.

> node ./src/temp.js --loglevel 2
> node ./src/temp.js --loglevel debug

Type declaration

  • _level: number
  • debug: ((...values) => void)
      • (...values): void
      • Displays the passed in strings on the console provided log level is 4 or higher

        Parameters

        • Rest ...values: (undefined | null | string | number)[]

          strings, numbers, nulls, undefined all concatenated with space separator to form the log message

        Returns void

  • error: ((...values) => void)
      • (...values): void
      • Displays the passed in strings on the console provided log level is 1 or higher

        Parameters

        • Rest ...values: (undefined | null | string | number)[]

          strings, numbers, nulls, undefined all concatenated with space separator to form the log message

        Returns void

  • getLevel: (() => number)
      • (): number
      • Current Logging Level:

        • 0 silent
        • 1 errors
        • 2 warnings & errors
        • 3 info, success, warnings & errors
        • 4 debug and level 3
        • 5 all including trace

        Returns number

        current logging level as a numeric (0 - 5)

  • info: ((...values) => void)
      • (...values): void
      • Displays the passed in strings on the console provided log level is 3 or higher

        Parameters

        • Rest ...values: (undefined | null | string | number)[]

          strings, numbers, nulls, undefined all concatenated with space separator to form the log message

        Returns void

  • setLevel: ((level) => void)
      • (level): void
      • Sets the current logging level. Possible values are:

        1. 'silent' or 0
        2. 'error' or 1
        3. 'warn' or 2
        4. 'notice', 'http', 'info', 'success' or 3
        5. 'debug', 'verbose' or 4
        6. 'trace', 'silly' or 5 -1 resets log level to that set by the command line

        Parameters

        • level: string | number | boolean

          string or numeric representing the required level of logging

        Returns void

  • success: ((...values) => void)
      • (...values): void
      • Displays the passed in strings on the console provided log level is 3 or higher

        Parameters

        • Rest ...values: (undefined | null | string | number)[]

          strings, numbers, nulls, undefined all concatenated with space separator to form the log message

        Returns void

  • trace: ((...values) => void)
      • (...values): void
      • Displays the passed in strings on the console together with the stack trace provided log level is 5

        Parameters

        • Rest ...values: (undefined | null | string | number)[]

          strings, numbers, nulls, undefined all concatenated with space separator to form the log message

        Returns void

  • warn: ((...values) => void)
      • (...values): void
      • Displays the passed in strings on the console provided log level is 2 or higher

        Parameters

        • Rest ...values: (undefined | null | string | number)[]

          strings, numbers, nulls, undefined all concatenated with space separator to form the log message

        Returns void

Generated using TypeDoc