rework config and logger
This commit is contained in:
		@@ -1,7 +1,27 @@
 | 
			
		||||
import dotenv from "dotenv"
 | 
			
		||||
dotenv.config()
 | 
			
		||||
 | 
			
		||||
export const config = {
 | 
			
		||||
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: {
 | 
			
		||||
@@ -19,12 +39,14 @@ export const config = {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  bot: {
 | 
			
		||||
    debug: true,
 | 
			
		||||
	port: 1234,
 | 
			
		||||
    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 ?? ""
 | 
			
		||||
    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" })
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user