c4cc-logging
v1.0.0
Published
A logging framework that allows injection of custom logging strategies as a means to configure logging.
Downloads
26
Readme
c4cc-logging
This module provides a pluggable logging framework by allowing different logging strategies to be injected. This will allow consumers to swap logging strategies in and out of a consuming module with minimal changes.
installation
TBD
usage
Minimalist
const {C4CCLogging} = require('c4cc-logging');
const logManager = new C4CCLogging();
const logger = logManager.getLogger();
logger.error('error log message');
logger.warn('warn log message');
logger.info('info log message');
logger.debug('debug log message');
logger.log('default log message'); //generic log() uses info() for ConsoleLoggingStrategy
The default logging strategy if none is specified is in the internal ConsoleLoggingStrategy.
custom logging strategies
The logging strategy and default logging level can be specified in the constructor. The default logging level is the level that new loggers will be created with if no level is specified in the call to getLogger();
const {C4CCLogging, LEVELS} = require('c4cc-logging');
const myLoggingStrategy = ...;
const logManager = new C4CCLogging(myLoggingStrategy, LEVELS.warn);
const defaultLogger = logManager.getLogger(); // this logger will use the default specified above - LEVELS.warn
const logger = logManager.getLogger('my-log-component', LEVELS.debug); // log all messages from this particular logger since it overrides to LEVELS.debug.
Usage of Log4JS is supported via the c4cc-logging-log4j
module - see the c4cc-logging-log4js
README.md for more info.
const {C4CCLogging, LEVELS} = require('c4cc-logging');
const Log4JsLoggingStrategy = require('c4cc-logging-log4js');
const log4JSStrategy = new Log4JsLoggingStrategy();
const logManager = new C4CCLogging(log4JSStrategy);
const defaultLogger = logManager.getLogger();