refactor(api/utils): improve logger

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-05 02:05:52 -04:00
parent 4c39eb8799
commit ac6dc8ed09
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -1,15 +1,15 @@
import winston from "winston";
const { combine, timestamp, simple, splat, printf, colorize } = winston.format;
const { combine, timestamp, json, splat, printf, colorize } = winston.format;
winston.add;
const fmt = printf(({ timestamp, level, message, meta }) => {
return `${timestamp} [${level}] ------ ${message} ${
!!meta.durationMs ? "\n (took) " + meta.durationMs + "ms" : ""
const fmt = printf(({ timestamp, level, message, label, durationMs }) => {
return `${timestamp} [${label || "misc"}] ${message} ${
!!durationMs ? " (took " + durationMs + "ms)" : ""
}`;
});
const cfmt = combine(colorize(), timestamp(), splat(), fmt);
const cfmt = combine(json(), timestamp(), fmt);
const loggerTransports: any[] = [
new winston.transports.Console({
@ -25,20 +25,15 @@ process.env.NODE_ENV?.toLowerCase() == "development" &&
new winston.transports.File({
filename: "/var/log/rockfic.debug.log",
level: "debug",
format: combine(timestamp(), splat(), fmt),
format: combine(timestamp(), fmt),
handleExceptions: true,
handleRejections: true,
}),
);
const logger = winston.createLogger({
levels: winston.config.syslog.levels,
levels: { ...winston.config.syslog.levels, silly: 8 },
transports: loggerTransports,
format: cfmt,
});
// app.listen(7000, () => logger.debug("fuckyou"))
// console.log(api.stack)
export const log = logger;