1.0.1 • Published 3 years ago

c4cc-logging-log4js v1.0.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
3 years ago

c4cc-logging-log4js

This module provides a logging strategy for the c4cc-logging framework that uses log4js-node.

installation

TBD

usage

Minimalist

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();

The default strategy uses the default log4JS appender which is the console.

The Log4JsLoggingStrategy accepts a standard log4js configuration object in the constructor which will allow for module specific configuration of logging.

const {C4CCLogging, LEVELS} = require('c4cc-logging');
const Log4JsLoggingStrategy = require('c4cc-logging-log4js');

const log4JSStrategy = new Log4JsLoggingStrategy({
  appenders: {c4cc: {type: 'file', filename: 'c4cc.log'}},
  categories: {default: {appenders: ['c4cc'], level: 'error'}},
});
const logManager = new C4CCLogging(log4JSStrategy);
const c4ccLogger = logManager.getLogger('c4cc');
const customModuleLogger = logManager.getLogger('my-custom-module-logger', LEVELS.DEBUG);  //creates a log4js logger which will use the default category with level set to DEBUG so that everything will be logged

The example above will log to a flat file, c4cc.log by default instead of the console, and specifies that only error or higher messages should be logged.

See the log4js-node README for more information on log4js capabilities: https://github.com/log4js-node/log4js-node/blob/master/README.md