Skip to content

Commit

Permalink
[logging] log sender ip address
Browse files Browse the repository at this point in the history
  • Loading branch information
nleush committed Mar 29, 2016
1 parent 2b9d6fc commit 41c773f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ var moment = require('moment');

exports.log = function() {
var args = Array.prototype.slice.apply(arguments);

// Add ip if request provided.
var request = args[0];
if (request && request.headers) {
args.shift();
var remote_addr = request.headers['x-forwarded-for'] || request.connection.remoteAddress;
if (remote_addr) {
args.splice(0, 0, remote_addr, '-');
}
}

args.splice(0, 0, "--", moment().utc().format("\\[YY-MM-DD HH:mm:ss\\]"));

console.log.apply(console, args);
};
8 changes: 4 additions & 4 deletions modules/api/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = function(app) {
return next(new Error("local domains not supported"));
}

log('Loading /iframely for', uri);
log(req, 'Loading /iframely for', uri);

async.waterfall([

Expand Down Expand Up @@ -188,7 +188,7 @@ module.exports = function(app) {
return next(new Error("local domains not supported"));
}

log('Loading /reader for', uri);
log(req, 'Loading /reader for', uri);

async.waterfall([

Expand Down Expand Up @@ -251,7 +251,7 @@ module.exports = function(app) {
return next(new Error("local domains not supported"));
}

log('Loading /render for', uri);
log(req, 'Loading /render for', uri);

async.waterfall([

Expand Down Expand Up @@ -366,7 +366,7 @@ module.exports = function(app) {
return next(new Error("local domains not supported"));
}

log('Loading /oembed for', uri);
log(req, 'Loading /oembed for', uri);

async.waterfall([

Expand Down
2 changes: 1 addition & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@

if (head) {

log("Using cache for", req.url.replace(/\?.+/, ''), req.query.uri || req.query.url);
log(req, "Using cache for", req.url.replace(/\?.+/, ''), req.query.uri || req.query.url);

var requestedEtag = req.headers['if-none-match'];

Expand Down

0 comments on commit 41c773f

Please sign in to comment.