1.0.5 • Published 7 years ago

cls-named-logger v1.0.5

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

CLS Named Logger Build Status

Installtion

npm install cls-named-logger

Usage

const loggerFactory = require('cls-named-logger')();
const logger = loggerFactory('debug:namespace');

const clsNamespace = loggerFactory.clsNs;

clsNamespace.run(function() {
    clsNamespace.set('customArg', 123);
    logger.log('Some message');
});

or

const cls = require('continuation-local-storage');
const clsNamedLogger = require('cls-named-logger');

const clsNamespace = cls.createNamespace(clsNamespaceName);
const logger = clsNamedLogger(clsNamespace)('debug:namespace');

clsNamespace.run(function() {
    clsNamespace.set('customArg', 123);
    logger.log('Some message');
});

It will append custom CLS namespace values to the end of the message. In :point-up: example it will be:

Some message [customArg=123]

It exposes the same log levels as console, which are: ['log', 'info', 'debug', 'trace', 'warn', 'error']