mongoose-events-event-logger
v0.1.1
Published
creates a mongoose event handler that logs mongoose events for the given event type
Downloads
3
Maintainers
Readme
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 {string} event_type
* @param {Object} db_connection
* @param {Object} [custom_logger]
*
* @return {Function} logEvent
*/
createEventLogger( event_type, db_connection, custom_logger )
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 = require( 'mongoose-events-event-logger' )
var db
db = mongoose.connection
db.on( 'connected', createEventLogger( 'connected', db ) )
with a custom logger
var eventLogger = require( 'mongoose-events-event-logger' )
var db
// logging service needs to have a .log( arg1[, arg2[, ...] ] ) method
var logger = require( 'your-custom-logger' )
db = mongoose.connection
db.on( 'connected', createEventLogger( 'connected', db, logger ) )