lazy-common
Common libraries and utilities for lazy
LazyLoggingLevels
Using this object ensures consistent logging levels across all lazy processes running in Node.
Use:
const common = require('@getlazy/common');
const winston = require('winston');
winston.addColors(common.LazyLoggingLevels.colors);
const logger = new winston.Logger({
levels: common.LazyLoggingLevels.levels
});
PackageLogger
External packages cannot know if logger
exists on the global level nor what are its levels. This replaces such logging efforts with emitting log
events and leaving it to the package's user to listen to these events.
Use:
const common = require('@getlazy/common');
const logger = common.createLogger('my-package');
logger.info('Succeeded marvelously.');
Forwarding log events:
const myPackage = require('my-package');
myPackage.logger.on('log', (level, packageName, ...args) => {
const argsWithoutMeta = [...args];
const meta = argsWithoutMeta.pop();
if (typeof(meta) === 'object') {
if (!meta._packageName) {
meta._packageName = packageName;
}
}
logger.log(level, ...messages, meta);
})