From fa47a2d86c79f46314e29671cae931b46fa9d8b3 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 21 Aug 2026 08:11:48 -0700 Subject: [PATCH] Chore: again, improve k8s error logging --- src/utils/logger.js | 19 ++++++------------- src/utils/logger.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/utils/logger.js b/src/utils/logger.js index 74dfaf9bc..5f12de077 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -18,23 +18,16 @@ function combineMessageAndSplat() { } function messageFormatter(logInfo) { - if (logInfo.label) { - if (logInfo.stack) { - return `[${logInfo.timestamp}] ${logInfo.level}: <${logInfo.label}> ${logInfo.stack}`; - } - return `[${logInfo.timestamp}] ${logInfo.level}: <${logInfo.label}> ${logInfo.message}`; - } - - if (logInfo.stack) { - return `[${logInfo.timestamp}] ${logInfo.level}: ${logInfo.stack}`; - } - return `[${logInfo.timestamp}] ${logInfo.level}: ${logInfo.message}`; + const label = logInfo.label ? `<${logInfo.label}> ` : ""; + // e.g. fetch errors say nothing useful without the cause + const cause = logInfo.cause ? `\ncaused by: ${logInfo.cause.stack ?? logInfo.cause}` : ""; + return `[${logInfo.timestamp}] ${logInfo.level}: ${label}${logInfo.stack || logInfo.message}${cause}`; } function getConsoleLogger() { return new winston.transports.Console({ format: winston.format.combine( - winston.format.errors({ stack: true }), + winston.format.errors({ stack: true, cause: true }), combineMessageAndSplat(), winston.format.timestamp(), winston.format.colorize(), @@ -51,7 +44,7 @@ function getFileLogger() { return new winston.transports.File({ format: winston.format.combine( - winston.format.errors({ stack: true }), + winston.format.errors({ stack: true, cause: true }), combineMessageAndSplat(), winston.format.timestamp(), winston.format.printf(messageFormatter), diff --git a/src/utils/logger.test.js b/src/utils/logger.test.js index c1c441d58..350b24686 100644 --- a/src/utils/logger.test.js +++ b/src/utils/logger.test.js @@ -170,6 +170,16 @@ describe("utils/logger", () => { }); expect(plainMsg).toBe("[t] info: hello"); + const causeMsg = formatter({ + timestamp: "t", + level: "error", + label: "x", + stack: "STACK", + message: "fetch failed", + cause: { stack: "CAUSE STACK" }, + }); + expect(causeMsg).toBe("[t] error: STACK\ncaused by: CAUSE STACK"); + const out = splat.transform( { message: "Hello %s",