Skip to content

Commit

Permalink
fix(useLogger): avoid string substitution in non-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
andretchen0 committed Jan 13, 2024
1 parent a482ebe commit 3e2233c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/composables/useLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ interface LoggerComposition {

export function useLogger(): LoggerComposition {
function logError(...args: OneOrMore<any>) {
args[0] = logPrefix + args[0]
if (typeof args[0] === 'string') {
// NOTE: Don't break console string substitution
args[0] = logPrefix + args[0]
}
else {
args.unshift(logPrefix)
}
console.error(...args)
}

function logWarning(...args: OneOrMore<any>) {
args[0] = logPrefix + args[0]
if (typeof args[0] === 'string') {
// NOTE: Don't break console string substitution
args[0] = logPrefix + args[0]
}
else {
args.unshift(logPrefix)
}
console.warn(...args)
}

Expand Down

0 comments on commit 3e2233c

Please sign in to comment.