overleaf/services/web/app/coffee/infrastructure/Monitor/HTTP.coffee
Henry Oswald 3b1cc6e500 removed metrics from http logging but added key in
having the key in there means its easy to analyise the logs based on the
route
2014-04-30 13:14:41 +01:00

30 lines
1,012 B
CoffeeScript

settings = require("settings-sharelatex")
logger = require "logger-sharelatex"
os = require("os")
metrics = require("../Metrics")
module.exports.logger = (req, res, next) ->
startTime = new Date()
end = res.end
res.end = () ->
end.apply(this, arguments)
responseTime = new Date() - startTime
routePath = req.route.path.toString().replace(/\//g, '-').slice(1)
processName = if settings.internal.web.name? then "web-#{settings.internal.web.name}" else "web"
key = "#{os.hostname()}.#{processName}.#{routePath}".toLowerCase().trim()
logger.log
req:
url: req.originalUrl || req.url
method: req.method
key:key
referrer: req.headers['referer'] || req.headers['referrer']
"remote-addr": req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress
"user-agent": req.headers["user-agent"]
"content-length": req.headers["content-length"]
res:
"content-length": res._headers?["content-length"]
"response-time": responseTime
"http request"
next()