2023-04-15 22:06:35 +02:00
|
|
|
import { createLogger, format, transports } from "winston"
|
|
|
|
import { config } from "./configuration"
|
2023-11-18 16:42:27 +01:00
|
|
|
import { v4 } from "uuid"
|
|
|
|
export function newRequestId() { return v4() }
|
|
|
|
export const noGuildId = 'NoGuildId'
|
2023-04-15 22:06:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
const printFn = format.printf(({ guildId, level, message, errorCode, requestId, timestamp: logTimestamp }: { [k: string]: string }) => {
|
2023-06-24 21:05:43 +02:00
|
|
|
return `[${guildId ?? ''}][${level}][${logTimestamp}][${errorCode ?? ''}][${requestId ?? ''}]:${message}`
|
2023-04-15 22:06:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const logFormat = format.combine(
|
2023-06-24 21:05:43 +02:00
|
|
|
format.timestamp(),
|
|
|
|
printFn
|
2023-04-15 22:06:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const consoleTransports = [
|
2023-06-24 21:05:43 +02:00
|
|
|
new transports.Console({
|
2023-11-18 16:42:27 +01:00
|
|
|
format: logFormat,
|
|
|
|
silent: process.env.NODE_ENV === 'testing'
|
2023-06-24 21:05:43 +02:00
|
|
|
})
|
2023-04-15 22:06:35 +02:00
|
|
|
]
|
2023-04-16 02:02:15 +02:00
|
|
|
export const logger = createLogger({
|
2023-06-24 21:05:43 +02:00
|
|
|
level: config.bot.debug ? 'debug' : 'info',
|
|
|
|
format: logFormat,
|
|
|
|
silent: config.bot.silent,
|
|
|
|
transports: consoleTransports
|
2023-04-15 22:06:35 +02:00
|
|
|
})
|