jellyfin-discord-bot/server/logger.ts
kenobi 9cdc6e1934
Some checks failed
Compile the repository / compile (pull_request) Successful in 39s
Run unit tests / test (pull_request) Failing after 45s
add fake env vars for unit tests
2023-10-24 22:39:57 +02:00

29 lines
817 B
TypeScript

import { createLogger, format, transports } from "winston"
import { config } from "./configuration"
import { v4 } from "uuid"
export function newRequestId() { return v4() }
export const noGuildId = 'NoGuildId'
const printFn = format.printf(({ guildId, level, message, errorCode, requestId, timestamp: logTimestamp }: { [k: string]: string }) => {
return `[${guildId ?? ''}][${level}][${logTimestamp}][${errorCode ?? ''}][${requestId ?? ''}]:${message}`
})
const logFormat = format.combine(
format.timestamp(),
printFn
)
const consoleTransports = [
new transports.Console({
format: logFormat,
silent: process.env.NODE_ENV === 'testing'
})
]
export const logger = createLogger({
level: config.bot.debug ? 'debug' : 'info',
format: logFormat,
silent: config.bot.silent,
transports: consoleTransports
})