u
This commit is contained in:
@@ -15,6 +15,17 @@ function logField(label, value, { skipEmpty = false } = {}) {
|
||||
httpLog.debug(prefix + '\n' + rendered.replace(/^/gm, ' '));
|
||||
}
|
||||
|
||||
function logResponse(value) {
|
||||
const rendered = prettyJson(value).replace(/\r?\n/g, '');
|
||||
const prefix = chalk.gray(' response: ');
|
||||
if (rendered.length <= 100) {
|
||||
httpLog.debug(prefix + rendered);
|
||||
return;
|
||||
}
|
||||
const cut = rendered.length - 100;
|
||||
httpLog.debug(prefix + rendered.slice(0, 100) + '\u001b[0m' + chalk.gray(` … [${cut} chars cut]`));
|
||||
}
|
||||
|
||||
function captureResponseBody(res) {
|
||||
let body;
|
||||
const originalJson = res.json.bind(res);
|
||||
@@ -76,7 +87,7 @@ export const loggerMiddleware = (req, res, next) => {
|
||||
httpLog.debug(chalk.gray(' authorization: ') + chalk.cyan(req.headers.authorization));
|
||||
}
|
||||
logField('body', req.body ?? {}, { skipEmpty: true });
|
||||
logField('response', getBody());
|
||||
logResponse(getBody());
|
||||
|
||||
// Dump full request/response/error details to a log file on 5xx.
|
||||
const statusCode = res.statusCode;
|
||||
|
||||
Reference in New Issue
Block a user