@@ -3,19 +3,35 @@ export const isProd = import.meta.env.MODE === 'production'
3
3
4
4
const logPrefix = '[TresJS ▲ ■ ●] '
5
5
6
+ type OneOrMore < T > = { 0 : T } & Array < T >
7
+
6
8
interface LoggerComposition {
7
- logError : ( message : string , error ?: Error | ErrorEvent ) => void
8
- logWarning : ( message : string ) => void
9
+ logError : ( ... args : OneOrMore < any > ) => void
10
+ logWarning : ( ... args : OneOrMore < any > ) => void
9
11
logMessage : ( name : string , value : any ) => void
10
12
}
11
13
12
14
export function useLogger ( ) : LoggerComposition {
13
- function logError ( message : string , error ?: Error | ErrorEvent ) {
14
- console . error ( `${ logPrefix } ${ message } ` , error || '' )
15
+ function logError ( ...args : OneOrMore < any > ) {
16
+ if ( typeof args [ 0 ] === 'string' ) {
17
+ // NOTE: Don't break console string substitution
18
+ args [ 0 ] = logPrefix + args [ 0 ]
19
+ }
20
+ else {
21
+ args . unshift ( logPrefix )
22
+ }
23
+ console . error ( ...args )
15
24
}
16
25
17
- function logWarning ( message : string ) {
18
- console . warn ( `${ logPrefix } ${ message } ` )
26
+ function logWarning ( ...args : OneOrMore < any > ) {
27
+ if ( typeof args [ 0 ] === 'string' ) {
28
+ // NOTE: Don't break console string substitution
29
+ args [ 0 ] = logPrefix + args [ 0 ]
30
+ }
31
+ else {
32
+ args . unshift ( logPrefix )
33
+ }
34
+ console . warn ( ...args )
19
35
}
20
36
21
37
function logMessage ( name : string , value : any ) {
0 commit comments