@allgemein/logging
v1.2.1
Published
`@allgemein/logging` is a lightweight, generic logging facade for node and Typescript projects. It provides a single static `Logger` entry point that manages named logger instances and delegates the actual output to a pluggable implementation (a `ConsoleL
Downloads
445
Readme
@allgemein/logging
@allgemein/logging is a lightweight, generic logging facade for node and
Typescript projects. It provides a single static Logger entry point that
manages named logger instances and delegates the actual output to a pluggable
implementation (a ConsoleLogger is provided out of the box), so consuming
libraries don't need to depend on a concrete logging backend.
Install
npm i @allgemein/loggingUsage
import {Logger} from '@allgemein/logging';
Logger.info('application started');
Logger.warn('deprecated option used');
Logger.error('something went wrong');
// get a named/contextual logger instance
const logger = Logger.getLogger({context: 'my-module', type: 'console'});
logger.setLevel('debug');
logger.debug('detailed diagnostic information');Adding a custom logger implementation
import {Logger, AbstractLogger} from '@allgemein/logging';
class MyLogger extends AbstractLogger {
log(level: number | string, ...msg: any[]): void {
// forward to your favourite logging backend
}
}
Logger.addType('my-logger', MyLogger);
const logger = Logger.getLogger({context: 'default', type: 'my-logger'});Features
- Typescript support
- Static
Loggerfacade withinfo/warn/error/debug/trace/logmethods - Named/contextual logger instances via
Logger.getLogger({context, type}) ConsoleLoggerimplementation included by default- Extendable through
AbstractLoggerandLogger.addType(...)to plug in custom backends - Configurable log levels through
ILoggerApi.setLevel/getLevel
