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