jellyfin-discord-bot/server/logger.ts

25 lines
672 B
TypeScript
Raw Permalink Normal View History

2023-04-15 22:06:35 +02:00
import { createLogger, format, transports } from "winston"
import { config } from "./configuration"
const printFn = format.printf(({ guildId, level, message, errorCode, requestId, timestamp: logTimestamp }: { [k: string]: string }) => {
2023-04-16 02:02:15 +02:00
return `[${guildId ?? ''}][${level}][${logTimestamp}][${errorCode ?? ''}][${requestId ?? ''}]:${message}`
2023-04-15 22:06:35 +02:00
})
const logFormat = format.combine(
format.timestamp(),
printFn
)
const consoleTransports = [
new transports.Console({
format: logFormat
})
]
2023-04-16 02:02:15 +02:00
export const logger = createLogger({
level: config.bot.debug ? 'debug' : 'info',
2023-04-15 22:06:35 +02:00
format: logFormat,
2023-04-16 02:02:15 +02:00
silent: config.bot.silent,
2023-04-15 22:06:35 +02:00
transports: consoleTransports
})