-
Notifications
You must be signed in to change notification settings - Fork 4
/
logging.js
20 lines (16 loc) · 628 Bytes
/
logging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import {stdSerializers} from 'pino'
import _shorthash from 'shorthash'
const {unique: shorthash} = _shorthash
import pinoHttp from 'pino-http'
const reqSerializer = stdSerializers.req
const withoutRemoteAddress = (req) => {
const log = reqSerializer(req)
if (req.headers['x-identifier']) log.remoteAddress = req.headers['x-identifier']
else if (log.remoteAddress) log.remoteAddress = shorthash(log.remoteAddress)
return log
}
const serializers = Object.assign({}, stdSerializers, {req: withoutRemoteAddress})
const createLoggingMiddleware = logger => pinoHttp({logger, serializers})
export {
createLoggingMiddleware,
}