csquared/node-logfmt

logfmt.requestLogger() never logs x-forwarded-for

preflightsiren opened this issue · 2 comments

I'm looking at adding logging to an express app
I simply have it loaded with:

app.use logfmt.requestLogger()

when I use curl to request a route

curl -I -H "X-Forwarded-For: 1.1.1.1" localhost:5000

the output is:

ip=127.0.0.1 time=2014-01-06T23:36:01.576Z method=HEAD path=/ status=200 content_length=50754 content_type="text/html; charset=utf-8" elapsed=261ms

I patched requst_logger.js:12 to

var ip = httpHeader || req.connection.remoteAddress;

and now it's correctly printing the right ip.

What's the role of req.ip ? I can't see it in the nodejs API docs

found http://stackoverflow.com/questions/19266329/node-js-get-clients-ip that states req.ip is a part of express - need to investigate

yeah it's part of express https://github.com/visionmedia/express/blob/master/test/req.ip.js?source=c details the expected behaviour.

in my case I needed to provide add

app.enable('trust proxy');