Skip to content

Commit

Permalink
fix: util.format list issue
Browse files Browse the repository at this point in the history
  • Loading branch information
iowillhoit committed Jul 9, 2024
1 parent 4379357 commit ceb7cbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,16 @@ export class Messages<T extends string> {
}
const messages = ensureArray(msg);
return messages.map((message) => {
ensureString(message);
return util.format(message, ...tokens);
const msgStr = ensureString(message);
// If the message does not contain a specifier, util.format still appends the token to the end.
// The 'markdownLoader' automatically splits bulleted lists into arrays.
// This causes the token to be appended to each line regardless of the presence of a specifier.
// Here we check for the presence of a specifier and only format the message if one is present.
// https://nodejs.org/api/util.html#utilformatformat-args
// https://regex101.com/r/8Hf8Z6/1
const specifierRegex = new RegExp('%[sdifjoO]{1}', 'gm');

return specifierRegex.test(msgStr) ? util.format(msgStr, ...tokens) : msgStr;
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/messagesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ describe('Messages', () => {

it('should return single string from array of messages', () => {
expect(messages.getMessage('manyMsgs', ['blah', 864])).to.equal(
`hello blah 864${EOL}world blah 864${EOL}test message 2 blah and 864`
`hello${EOL}world${EOL}test message 2 blah and 864`
);
});

it('should return multiple string from array of messages', () => {
expect(messages.getMessages('manyMsgs', ['blah', 864])).to.deep.equal([
'hello blah 864',
'world blah 864',
'hello',
'world',
'test message 2 blah and 864',
]);
});
Expand Down

2 comments on commit ceb7cbd

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: ceb7cbd Previous: 5c6779c Ratio
Child logger creation 467786 ops/sec (±2.51%) 478191 ops/sec (±1.84%) 1.02
Logging a string on root logger 713866 ops/sec (±6.52%) 870280 ops/sec (±12.27%) 1.22
Logging an object on root logger 518093 ops/sec (±8.79%) 628199 ops/sec (±7.83%) 1.21
Logging an object with a message on root logger 15000 ops/sec (±188.77%) 1607 ops/sec (±276.35%) 0.11
Logging an object with a redacted prop on root logger 460859 ops/sec (±8.91%) 457971 ops/sec (±10.17%) 0.99
Logging a nested 3-level object on root logger 353060 ops/sec (±5.65%) 392874 ops/sec (±6.21%) 1.11

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: ceb7cbd Previous: 5c6779c Ratio
Child logger creation 320268 ops/sec (±0.89%) 323567 ops/sec (±0.97%) 1.01
Logging a string on root logger 803241 ops/sec (±5.63%) 687021 ops/sec (±5.18%) 0.86
Logging an object on root logger 584711 ops/sec (±5.93%) 586627 ops/sec (±6.82%) 1.00
Logging an object with a message on root logger 6114 ops/sec (±205.43%) 11921 ops/sec (±189.24%) 1.95
Logging an object with a redacted prop on root logger 445908 ops/sec (±13.82%) 431254 ops/sec (±7.31%) 0.97
Logging a nested 3-level object on root logger 321399 ops/sec (±4.85%) 298934 ops/sec (±5.95%) 0.93

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.