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)}`); + } }; /**