This commit is contained in:
seb
2026-10-13 13:21:14 +02:00
parent 8acca998bc
commit 2de2bc0d90
9 changed files with 3516 additions and 6 deletions

View File

@@ -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;