1.1.0 • Published 8 years ago
namespaced-console-logger v1.1.0
Namespaced Console Logger
Minimal namespaced stdout / stderr logger with a timestamp for the browser and Node.js.
The logger satisfies three requirements below and attempts to do nothing else:
- Is small: has no dependencies & <50 loc (for the browser)
- Has a timestamp
- Has a namespace
Example output:
2015-08-10T20:09:20.526Z (namespace) INFO: Hello world!Usage
import createLoggers from 'namespaced-console-logger';
const loggers = createLoggers();
const logger = loggers.get('namespace');
logger.info('Hello %s!', 'world');createLoggers()takes a minimum logginglevel, which is one of:['info', 'warn', 'error']and defaults toinfo. For example if you selectwarn, allinfologs will be ignored.warnanderrorlogs will be displayed.
Support for formatting and arbitrary metadata
import createLoggers from 'namespaced-console-logger';
const loggers = createLoggers('info', '{{timestamp}} {{hostname}} {{calculatedValue}} ({{namespace}}) {{level}}:', { hostname: 'machinename', calculatedValue: () => { return 1 + 2; } });
const logger = loggers.get('namespace');
//2015-08-10T20:09:20.526Z machinename 3 (namespace) INFO: Hello world!
logger.info('Hello %s!', 'world');