2014-04-29 10:20:31 -04:00
|
|
|
settings = require("settings-sharelatex")
|
2014-02-12 05:23:40 -05:00
|
|
|
logger = require "logger-sharelatex"
|
2014-04-29 10:20:31 -04:00
|
|
|
os = require("os")
|
|
|
|
metrics = require("../Metrics")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
module.exports.logger = (req, res, next) ->
|
|
|
|
startTime = new Date()
|
|
|
|
end = res.end
|
|
|
|
res.end = () ->
|
|
|
|
end.apply(this, arguments)
|
2014-04-29 10:20:31 -04:00
|
|
|
responseTime = new Date() - startTime
|
|
|
|
routePath = req.route.path.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()
|
|
|
|
metrics.timing(key, responseTime, 0.2)
|
2014-02-12 05:23:40 -05:00
|
|
|
logger.log
|
|
|
|
req:
|
|
|
|
url: req.originalUrl || req.url
|
|
|
|
method: req.method
|
|
|
|
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"]
|
2014-04-29 10:20:31 -04:00
|
|
|
"response-time": responseTime
|
2014-02-12 05:23:40 -05:00
|
|
|
"http request"
|
|
|
|
next()
|
|
|
|
|