Skip to content

Commit

Permalink
fix(useLogger): remove '<empty string>' from log, allow any args and …
Browse files Browse the repository at this point in the history
…string substitution
  • Loading branch information
andretchen0 committed Jan 13, 2024
1 parent 2ec756c commit a482ebe
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/composables/useLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ export const isProd = import.meta.env.MODE === 'production'

const logPrefix = '[TresJS ▲ ■ ●] '

type OneOrMore<T> = { 0: T } & Array<T>

interface LoggerComposition {
logError: (message: string, error?: Error | ErrorEvent) => void
logWarning: (message: string) => void
logError: (...args: OneOrMore<any>) => void
logWarning: (...args: OneOrMore<any>) => void
logMessage: (name: string, value: any) => void
}

export function useLogger(): LoggerComposition {
function logError(message: string, error?: Error | ErrorEvent) {
console.error(`${logPrefix} ${message}`, error || '')
function logError(...args: OneOrMore<any>) {
args[0] = logPrefix + args[0]
console.error(...args)
}

function logWarning(message: string) {
console.warn(`${logPrefix} ${message}`)
function logWarning(...args: OneOrMore<any>) {
args[0] = logPrefix + args[0]
console.warn(...args)
}

function logMessage(name: string, value: any) {
Expand Down

0 comments on commit a482ebe

Please sign in to comment.