Skip to content

Commit

Permalink
feat: allow inspect object in debug console\n\nTODO: add a flag to di…
Browse files Browse the repository at this point in the history
…sable it when not using vscode
  • Loading branch information
neko-para committed Nov 1, 2023
1 parent 4cf392b commit b5fe10e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/main/utils/log/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function createLogger(name: string, output: (env: TLoggerEnv) => void) {
'',
...args
).slice(1),
objs: args,
},
}
output(env)
Expand All @@ -83,7 +84,9 @@ export function createLogger(name: string, output: (env: TLoggerEnv) => void) {
return [logger, ctrl] as const
}

export function createPresetFormatter(output: (out: { pretty: string; mono: string }) => void) {
export function createPresetFormatter(
output: (out: { pretty: string; mono: string; cons: [prefix: string, objs: any[]] }) => void
) {
return (env: TLoggerEnv) => {
const time = `${env.date.year.toString().padStart(4, '0')}-${env.date.month
.toString()
Expand All @@ -106,6 +109,14 @@ export function createPresetFormatter(output: (out: { pretty: string; mono: stri
`[${env.name} ${env.source.file} ${env.source.func}]`,
env.content.mono,
].join('\t'),
cons: [
[
time,
chalk.bold(env.level),
`[${chalk.bold(env.name)} ${env.source.file} ${env.source.func}]`,
].join('\t'),
env.content.objs,
],
})
}
}
1 change: 1 addition & 0 deletions packages/main/utils/log/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface TLoggerEnv {
content: {
pretty: string
mono: string
objs: any[]
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/main/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Logger {
this.log_file_ = createWriteStream(this.log_file_path_, { flags: 'a' })

const formatter = createPresetFormatter(out => {
console.log(out.pretty)
console.log(out.cons[0], ...out.cons[1])
this.log_file_.write(out.mono + '\n')
})

Expand Down

0 comments on commit b5fe10e

Please sign in to comment.