1.2.0 • Published 3 years ago

lib-logging v1.2.0

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

lib-logging

Test Publish

A node.js logging implementation.

Installation

npm install --save lib-logging

Usage

Example

const logging = require('lib-logging')
logging.log(1, 'server', 'Hello World')
// will log in console (and file):
// [NOTE - SERVER | Thu Feb 04 2021 21:13:16 GMT+0100 ] Hello World

If you would like to log also the origin of the message you can use:

const logging = require('lib-logging')
logging.log(1, 'server', 'Hello World', true)
// will log in console (and file):
// [NOTE - SERVER | Thu Feb 04 2021 21:13:16 GMT+0100 ] (/my/path:35 - myFunction) Hello World

By default lib-logging will store all loggings in ./logs/lib-logging.log. You can disable this feature by using the addOptions() function (see configuration for more details).

Possible parameters

The log() function takes four arguments. 1. level: The log level as number (1: Note, 2: Warning, 3: Error) 2. service: The corresponding service triggering the log function, by default ['server', 'cors', 'redis', 'lifesign', 'mariadb'] are possible values 3. msg: The message string to log 4. caller: Boolean value (default false) which provides additional information about the origin

Configuration

To modify the default values of lib-logging you can use the addOptions(options) function.

const options = {
  enableLogging: false,
  logToFile: {
    note: false
  },
  level: {
    debug: 4
  },
  services: ['my service'],
  globalCaller: false
};
log.addOptions(options);

By default all events will be loged in the file ./logs/lib-logging.log. You can disable this feature for each loglevel individual, by setting the property in logToFile to false or disable the whole feature globally by setting enableLogging to false.

// disable on loglevel
logging.addOptions({
  logToFile: {
    note: false
  }
});
// disabled on NOTE events
// disable globally, good idea by using lib-logging in a browser application
logging.addOptions({
  enableLogging: false
});

For debugging purposes, you can set the globalCaller property to true. This will ptovide the additional caller information on all log events.

1.2.0

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago