Skip to content

Commit

Permalink
don't recurse
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed May 26, 2024
1 parent 270bd11 commit 9e87bc5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import {LogMethod, Logger} from './types'

export const primitiveOrJsonLogger = getLoggerTransformer(method => {
const transformed: LogMethod = (...args) => {
if (args.length === 1 && Array.isArray(args[0])) {
args[0].forEach(item => transformed(item))
} else if (args.every(isPrimitive)) {
method(...args)
} else if (args.length === 1) {
method(JSON.stringify(args[0], null, 2))
} else {
method(JSON.stringify(args, null, 2))
}
export const primitiveOrJsonLogger = getLoggerTransformer(log => (...args) => {
if (args.length === 1 && Array.isArray(args[0])) {
args[0].forEach(item => log(item))
} else if (args.every(isPrimitive)) {
log(...args)
} else if (args.length === 1) {
log(JSON.stringify(args[0], null, 2))
} else {
log(JSON.stringify(args, null, 2))
}

return transformed
})

const isPrimitive = (value: unknown): value is string | number | boolean => {
Expand Down

0 comments on commit 9e87bc5

Please sign in to comment.