next/lib/server/logger.ts

41 lines
982 B
TypeScript
Raw Normal View History

import winston from "winston";
2023-10-05 02:05:52 -04:00
const { combine, timestamp, json, splat, printf, colorize } = winston.format;
winston.add;
2023-10-05 02:05:52 -04:00
const fmt = printf(({ timestamp, level, message, label, durationMs }) => {
return `${timestamp} [${label || "misc"}] ${message} ${
!!durationMs ? " (took " + durationMs + "ms)" : ""
}`;
});
2023-10-05 02:05:52 -04:00
const cfmt = combine(json(), timestamp(), fmt);
const loggerTransports: any[] = [
new winston.transports.Console({
format: cfmt,
handleExceptions: true,
handleRejections: true,
level: "silly",
// json: false
}),
];
process.env.NODE_ENV?.toLowerCase() == "development" &&
loggerTransports.push(
new winston.transports.File({
filename: "/var/log/rockfic.debug.log",
level: "silly",
2023-10-05 02:05:52 -04:00
format: combine(timestamp(), fmt),
handleExceptions: true,
handleRejections: true,
}),
);
const logger = winston.createLogger({
transports: loggerTransports,
levels: { ...winston.config.syslog.levels, silly: 8 },
});
export const log = logger;