mirror of
https://github.com/Xevion/xevion.dev.git
synced 2026-01-31 22:26:33 -06:00
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.
This commit is contained in:
+35
-20
@@ -1,6 +1,3 @@
|
||||
// Patch console methods to output structured JSON logs
|
||||
// This runs before the Bun server starts to ensure all console output is formatted
|
||||
|
||||
const originalConsole = {
|
||||
log: console.log,
|
||||
error: console.error,
|
||||
@@ -9,23 +6,41 @@ const originalConsole = {
|
||||
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(' ');
|
||||
|
||||
const logEntry = {
|
||||
timestamp: new Date().toISOString(),
|
||||
level: level,
|
||||
message: message,
|
||||
target: 'bun',
|
||||
};
|
||||
|
||||
originalConsole.log(JSON.stringify(logEntry));
|
||||
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);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user