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