-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 881 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
const morgan = require('morgan')
const stripHeader = require('./stripHeader')
const defaults = {
useAccessLog: false,
stripHeaders: [
'x-forwarded-for',
'referer'
],
format: ':remote-addr - :x-forwarded-for :remote-user [:date[iso]] ":method :url HTTP/:http-version" :status :res[content-length] ":referer" ":user-agent"',
morganOptions: {}
}
/**
* Configures the access log. At minimum, ensure options.enabled is set to true.
* @param {object} options
* @return {function}
*/
module.exports = function (options) {
options = Object.assign({}, defaults, options)
if (!options.useAccessLog) {
return function (req, res, next) { next() }
}
options.stripHeaders.forEach((header) => {
morgan.token(header, (req) => {
return stripHeader(req.get(header))
})
})
return morgan(options.format, options.morganOptions)
}