@vitalets/logger
v2.1.1
Published
Pure typescript logger with levels and prefix support
Downloads
23
Readme
@vitalets/logger
Pure typescript logger with support of prefix, levels, time measure and debug buffering.
Features
- prefix
- log levels
- time measure
- buffering debug messages
Usage
import { Logger } from '@vitalets/logger';
// create logger with prefix and level
const logger = new Logger({ prefix: '[db]:', level: 'info' });
// log as usual
logger.debug(42);
logger.log(42);
logger.info(42);
logger.warn(42);
logger.error(42);
// measure time
const result = await logger.logTime('fetching...',
() => fetch('http://example.com')
);
// OUTPUT:
// 'fetching...'
// 'fetching... (1.234s)'
// buffer debug messages
try {
logger.debug('hello'); // -> outputs nothing as level=info, but stores message in logger.debugBuffer
throw new Error('my error');
} catch (e) {
throw logger.flushDebugBufferToError(e); // attaches debug messages to error stack
}
Installation
npm i @vitalets/logger
Note: this package is ESM only
API
tbd
License
MIT @ Vitaliy Potapov