Skip to content

Commit

Permalink
fix(utils): do not suppose formatter first parameter to be string
Browse files Browse the repository at this point in the history
  • Loading branch information
mkermani144 committed Jun 26, 2024
1 parent 0f0d972 commit 16a204a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-cherries-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosenet-utils': patch
---

Fix issue of trying to format non-string values in `convertToPrintfFormat`
12 changes: 9 additions & 3 deletions packages/utils/lib/logger/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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)}`);
}
};

/**
Expand Down

0 comments on commit 16a204a

Please sign in to comment.