How can override the winston-mongodb log function?
I have a centralised log for multiple systems and I want to add some
standard meta data into the log that allows me to identify the system.
However, I only want to log the additional meta to winston-mongodb and NOT
to the console
I think the solution is to override the winston-mongodb log function and
insert the data at that point, rather than simply the logger.log function.
I can override the function but I cannot workout what I need to call needs
to be called to continue with the normal transport log
var winston = require('winston'),
util = require('util'),
fs = require('fs'),
MongoDB = require('winston-mongodb').MongoDB;
/*
* Main winston setup code here
*/
var mongoDbTransport = new (winston.transports.MongoDB)({
level: dbLogLevel,
db: config.db.dbname,
collection: dbLogName,
host: config.db.host,
port: config.db.port,
username: config.db.username,
password: config.db.password
});
mongoDbTransport.log = function(level) {
var args = Array.prototype.slice.call(arguments, 1),
callback = typeof args[args.length - 1] === 'function' ?
args.pop() : null,
meta = typeof args[args.length - 1] === 'object' ? args.pop()
: {},
msg = args[args.length - 1];
meta.systemName = status.name;
meta.systemVersion = status.version;
meta.system = status;
// here is the problem - what do I call here?
MongoDB.prototype.log(level, msg, meta, callback);
}
No comments:
Post a Comment