Files
xevion.dev/web/console-logger.js
Xevion 9de3c84f00 feat: add Docker containerization with multi-stage build
Includes .dockerignore, Dockerfile with cargo-chef caching, and Justfile commands for building/running containerized app. Updates console-logger to support both JSON and pretty-printed logs based on LOG_JSON env var.
2026-01-04 20:23:11 -06:00

47 lines
1.3 KiB
JavaScript

const originalConsole = {
log: console.log,
error: console.error,
warn: console.warn,
info: console.info,
debug: console.debug,
};
const useJson = process.env.LOG_JSON === "true" || process.env.LOG_JSON === "1";
function formatLog(level, args) {
const message = args
.map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg)))
.join(" ");
if (useJson) {
const logEntry = {
timestamp: new Date().toISOString(),
level: level,
message: message,
target: "bun",
};
originalConsole.log(JSON.stringify(logEntry));
} else {
const timestamp = new Date().toISOString().split("T")[1].slice(0, 12);
const levelColors = {
debug: "\x1b[36m", // cyan
info: "\x1b[32m", // green
warn: "\x1b[33m", // yellow
error: "\x1b[31m", // red
};
const color = levelColors[level] || "";
const reset = "\x1b[0m";
const gray = "\x1b[90m";
originalConsole.log(
`${gray}${timestamp}${reset} ${color}${level.toUpperCase().padEnd(5)}${reset} ${gray}bun${reset}: ${message}`,
);
}
}
console.log = (...args) => formatLog("info", args);
console.info = (...args) => formatLog("info", args);
console.warn = (...args) => formatLog("warn", args);
console.error = (...args) => formatLog("error", args);
console.debug = (...args) => formatLog("debug", args);