npm install cls-named-logger
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']