log4js-db-mongodb
TypeScript icon, indicating that this package has built-in type declarations

0.2.5 • Public • Published

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('restAppender');
    curentAppenders.push('just_errors');

    configure({
        appenders: {
            dbAppender: {
                type: 'log4js-db-mongodb',
                mongoSetting: {
                    url: 'mongodb+srv://logging:iyBQ4FxqWOHwQiOI@bull-wsttp.mongodb.net/messenger',
                    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

Package Sidebar

Install

npm i log4js-db-mongodb

Weekly Downloads

1

Version

0.2.5

License

ISC

Unpacked Size

26.6 kB

Total Files

22

Last publish

Collaborators

  • jirvra