mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 05:51:17 -07:00
Chore: again, improve k8s error logging
This commit is contained in:
+6
-13
@@ -18,23 +18,16 @@ function combineMessageAndSplat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function messageFormatter(logInfo) {
|
function messageFormatter(logInfo) {
|
||||||
if (logInfo.label) {
|
const label = logInfo.label ? `<${logInfo.label}> ` : "";
|
||||||
if (logInfo.stack) {
|
// e.g. fetch errors say nothing useful without the cause
|
||||||
return `[${logInfo.timestamp}] ${logInfo.level}: <${logInfo.label}> ${logInfo.stack}`;
|
const cause = logInfo.cause ? `\ncaused by: ${logInfo.cause.stack ?? logInfo.cause}` : "";
|
||||||
}
|
return `[${logInfo.timestamp}] ${logInfo.level}: ${label}${logInfo.stack || logInfo.message}${cause}`;
|
||||||
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}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConsoleLogger() {
|
function getConsoleLogger() {
|
||||||
return new winston.transports.Console({
|
return new winston.transports.Console({
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
winston.format.errors({ stack: true }),
|
winston.format.errors({ stack: true, cause: true }),
|
||||||
combineMessageAndSplat(),
|
combineMessageAndSplat(),
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp(),
|
||||||
winston.format.colorize(),
|
winston.format.colorize(),
|
||||||
@@ -51,7 +44,7 @@ function getFileLogger() {
|
|||||||
|
|
||||||
return new winston.transports.File({
|
return new winston.transports.File({
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
winston.format.errors({ stack: true }),
|
winston.format.errors({ stack: true, cause: true }),
|
||||||
combineMessageAndSplat(),
|
combineMessageAndSplat(),
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp(),
|
||||||
winston.format.printf(messageFormatter),
|
winston.format.printf(messageFormatter),
|
||||||
|
|||||||
@@ -170,6 +170,16 @@ describe("utils/logger", () => {
|
|||||||
});
|
});
|
||||||
expect(plainMsg).toBe("[t] info: hello");
|
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: <x> STACK\ncaused by: CAUSE STACK");
|
||||||
|
|
||||||
const out = splat.transform(
|
const out = splat.transform(
|
||||||
{
|
{
|
||||||
message: "Hello %s",
|
message: "Hello %s",
|
||||||
|
|||||||
Reference in New Issue
Block a user