From 9e87bc552c745ea1a242c3f976a6001742a86a3d Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Sun, 26 May 2024 10:09:22 -0400 Subject: [PATCH] don't recurse --- src/logging.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/logging.ts b/src/logging.ts index 4b70437..e171683 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -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 => {