Registry / devops / log4js-db-mongodb

log4js-db-mongodb

JSON →
library0.2.5jsnpmunverified

A MongoDB appender for log4js-node that allows logging events directly to a MongoDB collection. Current stable version is 0.2.5, with semver indicating early development. It wraps the MongoDB Node.js driver and integrates with log4js's configuration system. Key differentiator: a dedicated MongoDB appender for log4js, supporting filtered logging levels and custom layouts. Released under ISC license.

npm install log4js-db-mongodb
INSTALL
IMPORT
SIG · LOG4JS-DB-MONGODB
L
log4js-db-mongodb
devopsjavascriptv0.2.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

log4js-db-mongodb
import { configure } from 'log4js'; // then use type: 'log4js-db-mongodb' in config
const log4jsDbMongo = require('log4js-db-mongodb');
This package provides a log4js appender, not a direct import. It must be loaded by log4js via the type string in appender configuration.

Configures log4js with a MongoDB appender to log events to a remote database, including an example logger call.

import { configure, getLogger } from 'log4js'; configure({ appenders: { mongo: { type: 'log4js-db-mongodb', mongoSetting: { url: process.env.MONGO_URL ?? 'mongodb://localhost:27017', options: { useNewUrlParser: true, useUnifiedTopology: true }, database: 'logs', collection: 'log_entries', }, layout: { type: 'basic' }, }, }, categories: { default: { appenders: ['mongo'], level: 'INFO' } }, }); const logger = getLogger(); logger.info('App started');
Debug
Known issues
gotchaThe package version 0.2.5 still uses deprecated MongoDB connection options (useNewUrlParser, useUnifiedTopology) which are ignored in newer MongoDB driver versions.
fix
Remove useNewUrlParser and useUnifiedTopology options; they are ignored in MongoDB driver 4.0+.
affects: >=0.0.0
gotchaIn the example, the appender type is incorrectly named 'restAppender' in the appenders array, but configured as 'dbAppender'. This causes a configuration error.
fix
Ensure the appender name in categories matches the key used in appenders configuration.
affects: >=0.0.0
Errors
Common errors & fixes
Error: No appender 'dbAppender' found
Mismatch between appender name in categories and actual appender key.
fix
Use consistent naming: if you define appenders: { mongo: ... }, then categories should reference 'mongo'.
MongoParseError: options useNewUrlParser, useUnifiedTopology are not supported
Using outdated MongoDB connection options that are now ignored but may cause warnings.
fix
Remove useNewUrlParser and useUnifiedTopology from mongoSetting.options.
Upgrade
Version history
0.2.5latest on npm
Audit
Dependencies
log4jsrequiredlog4js-db-mongodb is an appender for log4js, so log4js is required to configure and use loggers.
mongodbrequiredUsed to connect to MongoDB and insert log documents.
Agent activity
10 hits · last 30 days
node
10
Resources
log4js-db-mongodb — npm install log4js-db-mongodb · libregistry