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