This package has been deprecated

Author message:

this package has been deprecated

digipolis-logger

2.0.2 • Public • Published

digipolis-logger

A logger that can be used to log to different winston logging transports.

Using the logger

const logger = require('digipolis-logger');
logger.setConfig(config);

logger.debug('Console shows debug in development environment!!!');
logger.log('Console shows log!!!');
logger.warn('Console shows warning!!!');
logger.error('Console shows error and added to error log!!!');

// With metadata
logger.info('Console show metadata as well', { more: 'info' });

Logger configuration

The logging engine requires a log object with predefined structure. In order to set a number of the properties in this object a configuration object must be supplied to the logger.

The sections header and body are mapped directly on the log object of the logging engine. You can consult the logger engine documentation for the details and meanings of these settings.

The endpoint setting must contain the endpoint of the logging engine, the apikey should contain the apikey obtained at the api store for your application.

The level property is the minimum log level that should be logged to the engine.

Here is an example of the configuration object to pass to the logger through the configLog method.

{
  "console": {
    "enabled": true,
    "level": "info"
  },
  "rotatingFile": {
    "enabled": false,
    "name": "error-file",
    "filename": "logs/error.log",
    "level": "error"
  },
  "acpaas": {
    "enabled": true,
    "endpoint": "localhost",
    "apikey": "apikey",
    "level": "debug",
    "header": {
      "index": "index",
      "version": "V3",
      "correlation": {
        "correlationId": "correlationId",
        "application": {
          "applicationId": "correlationAppId",
          "applicationName": "correlationAppName"
        },
        "instance": {
          "instanceId": "correlationInstanceId",
          "instanceName": "correlationInstanceName"
        }
      },
      "source": {
        "application": {
          "applicationId": "sourceAppId",
          "applicationName": "sourceAppName"
        },
        "instance": {
          "instanceId": "sourceInstanceId",
          "instanceName": "sourceInstanceName"
        },
        "component": {
          "componentId": "sourceComponentId",
          "componentName": "sourceComponentName"
        }
      }
    },
    "body": {
      "user": {
        "userName": "rc01608a",
        "ipAddress": "127.0.0.1"
      },
      "message": {
        "type": "text",
        "format": "plain-text"
      },
      "messageVersion": "1"
    }
  }
}

Default console transport

By default logging to the console is active with a loglevel of 'debug' for develpment environment and 'info' for other environments.

Disabling this default console transport can be done by calling the configLog method with a configuration object containing a console section with the enabled property set to 'false'.

{
  "console": {
    "enabled": false
  }
}

If you would like to change the default loglevel you can set the desired level in the config console section.

{
  "console": {
    "enabled": true,
    "level": "error"
  }
}

Acpaas logging transport

In order to log to the Acpaas logging engine, the transport must be enabled. This can be done by adding an 'acpaas' section on the configuration object.

When the 'enabled' property in this section is set to true, the acpaas logger is active.

The sections header and body are mapped directly on the log object of the logging engine. You can consult the logger engine documentation for the details and meanings of these settings.

The endpoint setting must contain the endpoint of the logging engine, the apikey should contain the apikey obtained at the api store for your application.

The level property is the minimum log level that should be logged to the engine.

Correlation

In case your application receives correlation info, this info can be passed to the logger using one of the log methods.

// The correlation info can be constructed or extracted from headers
const correlationInfo = ....

logger.log('Console shows log!!!', [metadata,] correlationInfo);


The correlation info object should have this structure:

{
    "id": "correlationId",
    "sourceId": "applicationId",
    "sourceName": "applicationName",
    "instanceId": "instanceId",
    "instanceName": "instanceName",
    "userId": "userName",
    "ipAddress": "ipAddress"
}

If no correlation info object is passed, the correlation info from the logger configuration is used.

Readme

Keywords

none

Package Sidebar

Install

npm i digipolis-logger

Weekly Downloads

0

Version

2.0.2

License

none

Last publish

Collaborators

  • frankdsm