Skip to content

Commit

Permalink
logging properly supports printing Uint8Array
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Feb 22, 2024
1 parent 5d1be5f commit 835c92b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Empty file removed environment.test.js
Empty file.
20 changes: 15 additions & 5 deletions logging.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as symbol from './symbol.js'
import * as time from './time.js'
import * as env from './environment.js'
import * as func from './function.js'
import * as json from './json.js'

export const BOLD = symbol.create()
export const UNBOLD = symbol.create()
Expand Down Expand Up @@ -63,11 +64,20 @@ export const createModuleLogger = (_print, moduleName) => {
color,
moduleName,
UNCOLOR,
...args.map((arg) =>
(typeof arg === 'string' || typeof arg === 'symbol')
? arg
: JSON.stringify(arg)
),
...args.map((arg) => {
if (arg != null && arg.constructor !== Uint8Array) {
arg = Array.from(arg)
}
const t = typeof arg
switch (t) {
case 'string':
case 'symbol':
return arg
default: {
return json.stringify(arg)
}
}
}),
color,
' +' + timeDiff + 'ms'
)
Expand Down

0 comments on commit 835c92b

Please sign in to comment.