Skip to content

Commit

Permalink
fix: logic in args mapping function
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored May 9, 2024
1 parent 8fc24cd commit fc9516d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const originalConsoleMethods: OriginalConsoleMethods = {
function interceptConsole(type: LogType): ConsoleMethod {
return (...args: any[]) => {
const timestampStyle = 'color: #4CAF50;'
const logMessage = `%c${getCurrentTimestamp()} - [${type.toUpperCase()}] - %c${ type === 'error' ? args.join(' ') : argsMapping(args)}`
const logMessage = `%c${getCurrentTimestamp()} - [${type.toUpperCase()}] - %c${argsMapping(args)}`
const resetStyle = 'color: inherit;'

originalConsoleMethods[type](logMessage, timestampStyle, resetStyle)
Expand All @@ -50,12 +50,20 @@ console.info = interceptConsole('info')

function storeLog(type: LogType, args: any[]): void {
try {
store.commit('addConsoleLog', { type, message: `${getCurrentTimestamp()} - [${type.toUpperCase()}] - ${ type === 'error' ? args.join(' ') : argsMapping(args)}` })
store.commit('addConsoleLog', { type, message: `${getCurrentTimestamp()} - [${type.toUpperCase()}] - ${argsMapping(args)}` })
} catch (error) {
console.error('Failed to store log:', error)
}
}

function argsMapping(args: any[]): string {
return args.map(arg => typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg).join(' ')
return args.map(arg => {
if (typeof arg === 'object' && arg !== null && 'message' in arg) {
return arg.message;

Check failure on line 62 in packages/ui/src/main.ts

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
} else if (typeof arg === 'object') {
return JSON.stringify(arg, null, 2)
} else {
return arg
}
}).join(' ')
}

0 comments on commit fc9516d

Please sign in to comment.