rework config and logger
This commit is contained in:
parent
e17c7601da
commit
f5be22fb6f
@ -1,30 +1,52 @@
|
||||
import dotenv from "dotenv"
|
||||
dotenv.config()
|
||||
|
||||
export const config = {
|
||||
server: {
|
||||
bodyParser: {
|
||||
urlEncodedOptions: {
|
||||
inflate: true,
|
||||
limit: '5mb',
|
||||
type: 'application/x-www-form-urlencoded',
|
||||
extended: true,
|
||||
parameterLimit: 1000
|
||||
},
|
||||
jsonOptions: {
|
||||
inflate: true,
|
||||
limit: '5mb',
|
||||
type: 'application/json',
|
||||
strict: true
|
||||
}
|
||||
}
|
||||
},
|
||||
debug: true,
|
||||
port: 1234,
|
||||
silent: false,
|
||||
token: process.env.BOT_TOKEN ?? "",
|
||||
guild_id: process.env.GUILD_ID ?? "",
|
||||
client_id: process.env.CLIENT_ID ?? "",
|
||||
jellfin_token:process.env.JELLYFIN_TOKEN ?? "",
|
||||
jellyfin_url:process.env.JELLYFIN_URL ?? ""
|
||||
interface options {
|
||||
[k: string]: boolean | number | string | undefined
|
||||
}
|
||||
interface bodyParserOptions {
|
||||
urlEncodedOptions: options,
|
||||
jsonOptions: options
|
||||
}
|
||||
export interface Config {
|
||||
server: { bodyParser: bodyParserOptions },
|
||||
bot: {
|
||||
debug: boolean
|
||||
silent: boolean
|
||||
token: string
|
||||
guild_id: string
|
||||
client_id: string
|
||||
jellfin_token: string
|
||||
jellyfin_url: string
|
||||
port: number
|
||||
}
|
||||
}
|
||||
export const config: Config = {
|
||||
server: {
|
||||
bodyParser: {
|
||||
urlEncodedOptions: {
|
||||
inflate: true,
|
||||
limit: '5mb',
|
||||
type: 'application/x-www-form-urlencoded',
|
||||
extended: true,
|
||||
parameterLimit: 1000
|
||||
},
|
||||
jsonOptions: {
|
||||
inflate: true,
|
||||
limit: '5mb',
|
||||
type: 'application/json',
|
||||
strict: true
|
||||
}
|
||||
}
|
||||
},
|
||||
bot: {
|
||||
debug: true,
|
||||
silent: false,
|
||||
port: 1234,
|
||||
token: process.env.BOT_TOKEN ?? "",
|
||||
guild_id: process.env.GUILD_ID ?? "",
|
||||
client_id: process.env.CLIENT_ID ?? "",
|
||||
jellfin_token: process.env.JELLYFIN_TOKEN ?? "",
|
||||
jellyfin_url: process.env.JELLYFIN_URL ?? ""
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,7 @@ 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}`
|
||||
return `[${guildId ?? ''}][${level}][${logTimestamp}][${errorCode ?? ''}][${requestId ?? ''}]:${message}`
|
||||
})
|
||||
|
||||
const logFormat = format.combine(
|
||||
@ -18,10 +16,9 @@ const consoleTransports = [
|
||||
format: logFormat
|
||||
})
|
||||
]
|
||||
const logger = createLogger({
|
||||
level: config.debug ? 'debug' : 'info',
|
||||
export const logger = createLogger({
|
||||
level: config.bot.debug ? 'debug' : 'info',
|
||||
format: logFormat,
|
||||
silent: config.silent,
|
||||
silent: config.bot.silent,
|
||||
transports: consoleTransports
|
||||
})
|
||||
logger.info("text", { requestId: "2", guildId: "asd" })
|
||||
|
Loading…
Reference in New Issue
Block a user