jellyfin-discord-bot/server/logger.ts
2023-04-15 22:06:35 +02:00

28 lines
757 B
TypeScript

import { createLogger, format, transports } from "winston"
import { config } from "./configuration"
const printFn = format.printf(({ guildId, level, message, errorCode, requestId, timestamp: logTimestamp }: { [k: string]: string }) => {
return `[${guildId}][${level}][${logTimestamp}][${errorCode
? `[${errorCode}]` : `[]`}][${requestId
? `[${requestId}]` : `[]`}]:${message}`
})
const logFormat = format.combine(
format.timestamp(),
printFn
)
const consoleTransports = [
new transports.Console({
format: logFormat
})
]
const logger = createLogger({
level: config.debug ? 'debug' : 'info',
format: logFormat,
silent: config.silent,
transports: consoleTransports
})
logger.info("text", { requestId: "2", guildId: "asd" })