Как мне зарегистрировать тело запроса (req.body) в объекте msg с помощью express-winston? - PullRequest
0 голосов
/ 28 октября 2019

Я пытаюсь войти в систему {{ req.body }} через express-winston 'msg: объект.

Я уже внес белый список в тело, используя expressWinston.requestWhitelist.push('body');, но он все еще отсутствует в журнале.

export const accessLogger = (router: Router) => {
    expressWinston.requestWhitelist.push('body');
    router.use(expressWinston.logger({
        level: "info";
        format: winston.format.simple(),
        transports: [
            new winston.transports.Console()
        ],
        meta: false,
        metaField: null!,
        msg: "HTTP {{ req.method }} {{ req.url }} {{ req.body }}",
        expressFormat: true
    }));
}

Использование:

curl -X POST -H "Accept: application/json" -d '{"test": "value"}' http://localhost:someport'

В данный момент в журнале выглядит так:

info: POST / 200 1ms

Должно выглядеть примерно так:

info: POST / 200 1ms {\"test\": \"value\"}

Если я включу meta, используя meta:true, я знаю и вижу, что он там есть:

info: POST / 200 1ms {"req":{"url":"/","headers":{"host":"localhost:someport","user-agent":"curl/7.63.0","accept":"application/json","content-length":"17","content-type":"application/x-www-form-urlencoded"},"method":"POST","httpVersion":"1.1","originalUrl":"/","query":{},"body":{"{\"test\": \"value\"}":""}},"res":{"statusCode":200},"responseTime":1}

Но я не хочу, чтобы вся мета заполняла мой журнал.

...