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