Loggerhythm
A winston-wrapper to log in a
debug-like manner including namespaces
Usage
Loggerhythm exports a Logger-class, whose instances have different log-functions for different log-levels.
the avaliable loglevels are:
- critical
- error
- warn
- info
- verbose
- debug
- silly
critical and error log to stderr
, everything else logs to stdout
!
Example
const Logger = require('loggerhythm').Logger;
const logger = new Logger('readme-namespace')
logger.info('foo');
logger.warn('bar');
The output would look like this (the different log-leves use different colors):
2016-08-30T14:06:33.751Z - info: [readme-namespace] foo
2016-08-30T14:06:33.752Z - warn: [readme-namespace] bar
Methods
Static
The Logger-Class has static methods, that can be used to globally set loggerhythm-config and register global log-hooks:
const Logger = require('loggerhythm').Logger;
const Loglevel = require('loggerhythm').LogLevel;
Logger.setLogLevel(LogLevel.WARN);
Logger.setMaxObjectLogDepth(3);
const subscription = Logger.subscribe((logLevel, namespace, message, ...logObjects) => {
});
subscription.dispose();
Instance-methods
The Instances of the Logger-class have a log-method for every loglevel and a subscribe-method to get informed about
logs of that instance
const Logger = require('loggerhythm').Logger;
const logger = new Logger('readme-namespace');
const subscription = Logger.subscribe((logLevel, namespace, message, ...logObjects) => {
});
logger.critical('critical log');
logger.error('error-log', new Error('hello'));
logger.warn('warning-log');
logger.info('have some info', {v1: 1, v2: 2, test: ['some', 'test', 'array']});
logger.verbose('some', 'more detailed', 'info');
logger.debug('denug-log');
logger.silly('some stupidly verbose log');
subscription.dispose();