Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
appenders = {},
// real loggers created for each entry in the config
loggers = [],
// cache of met channels, maps full channel names to corresponding loggers
channels = {};
// Layout for file loggers
//
// %d - date
// %p - log level
// %z - pid
// %c - category
// %m - message
//
let plainLayout = log4js.layouts.layout('pattern',
{ pattern: '[%d] [%p] %z %c - %m' }
);
// Layout for console loggers
//
// only difference is `%[`..`%]` - defines highlighted (coloured) part
//
let colouredLayout = log4js.layouts.layout('pattern',
{ pattern: '%[[%d] [%p] %z %c -%] %m' }
);
//
// define system (general) logger
//
N.logger = log4js.getLogger('system');
//
// %d - date
// %p - log level
// %z - pid
// %c - category
// %m - message
//
let plainLayout = log4js.layouts.layout('pattern',
{ pattern: '[%d] [%p] %z %c - %m' }
);
// Layout for console loggers
//
// only difference is `%[`..`%]` - defines highlighted (coloured) part
//
let colouredLayout = log4js.layouts.layout('pattern',
{ pattern: '%[[%d] [%p] %z %c -%] %m' }
);
//
// define system (general) logger
//
N.logger = log4js.getLogger('system');
//
// provide a wrapper to set global log level
//
N.logger.setLevel = function (level) {
level = log4js.levels[level.toUpperCase()];
log4js.setGlobalLogLevel(level);
module.exports = {
getLogger: getLogger,
getDefaultLogger: log4js.getDefaultLogger,
addAppender: log4js.addAppender,
loadAppender: log4js.loadAppender,
clearAppenders: log4js.clearAppenders,
configure: configure,
replaceConsole: log4js.replaceConsole,
restoreConsole: log4js.restoreConsole,
levels: log4js.levels,
setGlobalLogLevel: log4js.setGlobalLogLevel,
layouts: log4js.layouts,
appenders: log4js.appenders
};
function mongodbAppender(config) {
if (!config || !config.connectionString) {
throw new Error('connectionString is missing. Cannot connect to mongdb.');
}
var collection;
var cache = [];
var layout = config.layout || log4js.layouts.messagePassThroughLayout;
var collectionName = config.collectionName || 'log';
var connectionOptions = config.connectionOptions || {};
function ERROR(err) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.name = err.toString();
this.message = err.message || 'error';
}
function replaceKeys(src) {
var result = {};
function mixin(dest, source, cloneFunc) {
if (lxHelpers.isObject(source)) {
/**
some idea; maybe not so good:
support the pattern layout but make it as a json serialization ?
*/
var layouts = require('log4js').layouts;
module.exports = layouts;
var messagePassThroughLayout = layouts.messagePassThroughLayout;
/*
log4js logging event:
startTime: date,
categoryName: string,
level: { level: int, levelStr: levelStr },
data: [ args of logger ],
logger: ... circular ...
*/
/**
* Outputs a JSON object
return function(loggingEvent) {
var level = getSyslogLevel(loggingEvent.level)
, data = loggingEvent.data
, layout
if(level) {
layout = config && config.layout ? config.layout : log4js.layouts.basicLayout;
data = layout(loggingEvent);
syslog.log(level, data);
}
};
}