From 16a204a9d1c05b1c5c8c22e5a9243b21d720c269 Mon Sep 17 00:00:00 2001 From: Mohammad Kermani Date: Wed, 26 Jun 2024 16:15:16 +0000 Subject: [PATCH] fix(utils): do not suppose formatter first parameter to be string --- .changeset/pink-cherries-taste.md | 5 +++++ packages/utils/lib/logger/index.ts | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .changeset/pink-cherries-taste.md diff --git a/.changeset/pink-cherries-taste.md b/.changeset/pink-cherries-taste.md new file mode 100644 index 0000000..800da3b --- /dev/null +++ b/.changeset/pink-cherries-taste.md @@ -0,0 +1,5 @@ +--- +'@rosen-bridge/rosenet-utils': patch +--- + +Fix issue of trying to format non-string values in `convertToPrintfFormat` diff --git a/packages/utils/lib/logger/index.ts b/packages/utils/lib/logger/index.ts index 3afd127..e2c2048 100644 --- a/packages/utils/lib/logger/index.ts +++ b/packages/utils/lib/logger/index.ts @@ -1,3 +1,5 @@ +import { format as utilFormat } from 'node:util'; + import { ComponentLogger, Logger } from '@libp2p/interface'; import { AbstractLogger, DummyLogger } from '@rosen-bridge/logger-interface'; @@ -11,9 +13,13 @@ import format from './format'; */ const convertToPrintfFormat = (name: string, logger: AbstractLogger, level: 'info' | 'error' | 'debug') => - (formatter: string, ...rest: unknown[]) => { - const formatted = format(formatter, ...rest); - logger[level](`[${name}] ${formatted}`); + (formatter: unknown, ...rest: unknown[]) => { + if (typeof formatter === 'string') { + const formatted = format(formatter, ...rest); + logger[level](`[${name}] ${formatted}`); + } else { + logger[level](`[${name}] ${utilFormat(formatter, ...rest)}`); + } }; /**