log4js-db-mongodb-esnext
v2.0.5
Published
MongoDb Appender for log4js-node
Downloads
4
Readme
Rest Appender for log4js-node
Sends [log] events to a [mongodb]. This is an optional appender for use with log4js.
Configuration
npm install log4js-db-mongodb
npm install os
Example
import { configure, levels } from 'log4js';
import * as log4js from 'log4js';
const loggers: { [key: string]: log4js.Logger } = {};
/**
* @description Get logger with configuration
*/
export default function getLogger(category?: string): log4js.Logger {
if (!category) {
category = '';
}
if (loggers[category] === undefined) {
configureLog4js();
loggers[category] = log4js.getLogger(category);
}
return loggers[category];
}
/**
* @description Log4js konfiguration
*/
function configureLog4js(): void {
const curentAppenders: Array<string> = [];
curentAppenders.push('just_errors');
configure({
appenders: {
dbAppender: {
type: 'log4js-db-mongodb-esnext',
mongoSetting: {
url: 'your connection is here',
options: {
useNewUrlParser: true,
useUnifiedTopology: true,
ignoreUndefined: true,
},
database: 'messenger',
collection: 'log',
},
layout: {},
},
just_errors: {
type: 'logLevelFilter',
appender: 'dbAppender',
level: 'ERROR',
},
},
categories: {
default: {
appenders: curentAppenders,
level: 'DEBUG',
},
},
});
}
const logger = getLogger();
logger.warn('App start');
#Version - 0.2.3 - full promise - mongo 5.2.0 - log4js 6.9.1