add walletId and copayerId to log

This commit is contained in:
Matias Alejo Garcia 2015-09-29 10:54:06 -03:00
parent 5b4e69ef9c
commit ac5af8ed73
1 changed files with 18 additions and 5 deletions

View File

@ -56,11 +56,18 @@ ExpressApp.prototype.start = function(opts, cb) {
if (opts.disableLogs) {
log.level = 'silent';
} else {
// TODO access.log
//var accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})
//app.use(morgan('combined', {stream: accessLogStream}))
// app.use(require('morgan')('dev'));
this.app.use(require('morgan')(':remote-addr :date[iso] ":method :url" :status :res[content-length] :response-time ":user-agent" '));
var morgan = require('morgan');
morgan.token('walletId', function getId(req) {
return req.walletId
});
morgan.token('copayerId', function getId(req) {
return req.copayerId
});
this.app.use(morgan(' :remote-addr :date[iso] ":method :url" :status :res[content-length] :response-time ":user-agent" :walletId :copayerId'));
}
@ -127,6 +134,11 @@ ExpressApp.prototype.start = function(opts, cb) {
};
WalletService.getInstanceWithAuth(auth, function(err, server) {
if (err) return returnError(err, res, req);
// For logging
req.walletId = server.walletId;
req.copayerId = server.copayerId;
return cb(server);
});
};
@ -200,6 +212,7 @@ ExpressApp.prototype.start = function(opts, cb) {
getServerWithAuth(req, res, function(server) {
var opts = {};
if (req.query.includeExtendedInfo == '1') opts.includeExtendedInfo = true;
server.getStatus(opts, function(err, status) {
if (err) return returnError(err, res, req);
res.json(status);