Spaces:
Runtime error
Runtime error
File size: 929 Bytes
5710d63 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import fs from "node:fs";
import path from "node:path";
import winston from "winston";
const logsDir = path.join(process.cwd(), "logs");
fs.mkdirSync(logsDir, { recursive: true });
const runTimestamp = new Date().toISOString().replace(/[:.]/g, "-");
const { combine, colorize, errors, printf, timestamp } = winston.format;
const lineFormat = printf(({ level, message, timestamp: ts, stack }) => {
const base = `${ts} [${level}] ${message}`;
return stack ? `${base}\n${stack}` : base;
});
export const logger = winston.createLogger({
level: "debug",
transports: [
new winston.transports.Console({
format: combine(colorize({ all: true }), timestamp({ format: "HH:mm:ss" }), errors({ stack: true }), lineFormat),
}),
new winston.transports.File({
filename: path.join(logsDir, `app-${runTimestamp}.log`),
format: combine(timestamp(), errors({ stack: true }), lineFormat),
}),
],
});
|