Skip to content

Commit

Permalink
improvement in debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
nayvcake committed Dec 23, 2023
1 parent 9a820b9 commit 2b4c833
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ export class Logger {
messages_count++
console.log(`${chalk.gray(`[${messages_count}]`.padEnd(len, ' '))} ${chalk.bgBlueBright.white('[LOG]'.padEnd(7, ' '))} ${chalk.blueBright(`${this.pathName} ~`)} ${s(message.replace(process.cwd(), ''))} ${took == null ? '' : `[${chalk.gray.bold('timestamp:')}(${chalk.bgYellowBright.bold(`${(performance.now() - took).toFixed(2)}ms`)})]`}`)
}
debug(message: string, took?: number) {
debug(message: string, took?: number, ...obj: any) {
if (!process.argv.includes('--debug') && !process.argv.includes('-D')) return
messages_count++
console.debug(`${chalk.gray(`[${messages_count}]`.padEnd(len, ' '))} ${chalk.bgMagentaBright.whiteBright('[DEBUG]')} ${chalk.magentaBright(`${this.pathName} ~`)} ${s(message.replace(process.cwd(), ''))} ${took == null ? '' : `[${chalk.gray.bold('timestamp:')}(${chalk.bgYellowBright.bold(`${(performance.now() - took).toFixed(2)}ms`)})]`}`)
console.debug(chalk.gray(`[${messages_count}]`.padEnd(len, ' ')), chalk.bgMagentaBright.whiteBright('[DEBUG]'), chalk.magentaBright(`${this.pathName} ~`), s(message.replace(process.cwd(), '')), ...obj, took == null ? '' : `[${chalk.gray.bold('timestamp:')}(${chalk.bgYellowBright.bold(`${(performance.now() - took).toFixed(2)}ms`)})]`)
}
warn(message: string | Error, took?: number) {
warn(message: string | Error | any, ...obj: any) {
messages_count++
if (message instanceof Error) {
const msg = message.stack.split('\n')
msg.shift()
console.error(`\n${chalk.gray(`[${messages_count}]`.padEnd(len, ' '))} ${chalk.bgYellowBright.black('[WARN]')} ${chalk.yellowBright(`${this.pathName} ~`)} ${s(message.message.replace(process.cwd(), ''))} ${chalk.gray(msg.join('\n').replace(/(\([A-Za-z_0-9\-\\//!+\.:?]+\))/g, (a) => chalk.blueBright(a)))}\n`)

} else {
console.warn(`${chalk.gray(`[${messages_count}]`.padEnd(len, ' '))} ${chalk.bgYellowBright.black('[WARN]')} ${chalk.yellowBright(`${this.pathName} ~`)} ${s(message.replace(process.cwd(), ''))} ${took == null ? '' : `(${(performance.now() - took).toFixed(2)}ms)`}`)
console.warn(
chalk.gray(`[${messages_count}]`.padEnd(len, ' ')),
chalk.bgYellowBright.black('[WARN]'), chalk.yellowBright(`${this.pathName} ~`),
s(message.replace(process.cwd(), '')), ...obj)
}
}
info(message: string, took?: number) {
Expand Down
10 changes: 8 additions & 2 deletions src/discord/events/DebugListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ const logger = new Logger('DiscordPlatform.events.DebugListener')

export default {
name: 'debug',
run: async (_: ChinoClient, message: any) => {
logger.debug(message)
run: async (_: ChinoClient, message: any, id: any) => {
let data
try {
data = JSON.parse(message)
} catch {
data = message
}
logger.debug('', undefined, data, id ? `(id: ${id})` : '')
}
}

0 comments on commit 2b4c833

Please sign in to comment.