mongoose-events-logger
creates a mongoose event handler that logs mongoose events for the given event type using console.log
and console.error
.
table of contents
installation
npm install mongoose-events-event-logger
api
/** * @param * @param * @param * * @return */
event types
- connected
- connecting
- disconnected
- error
- open
- reconnected
usage
add an event logger to the mongoose db connection for each event type you want to log. the event logger will default to using the console
to log events, however, you can optionally pass in your own logging service.
the log message is composed using new Date()
and the db connection info; e.g. [info] %date connected to mongodb://%host:%port/%database
basic
var createEventLogger = var db db = mongooseconnectiondb
with a custom logger
var eventLogger = var db // logging service needs to have a .log( arg1[, arg2[, ...] ] ) methodvar logger = db = mongooseconnectiondb