Skip to content

Commit 9e5abf1

Browse files
authored
fix: add redaction to log format egress (#8529)
1 parent 3b54e9c commit 9e5abf1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/utils/format.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// All logging goes through here, both to console and log files
2+
13
const { formatWithOptions: baseFormatWithOptions } = require('node:util')
4+
const { redactLog } = require('@npmcli/redact')
25

36
// These are most assuredly not a mistake
47
// https://eslint.org/docs/latest/rules/no-control-regex
@@ -40,7 +43,7 @@ function STRIP_C01 (str) {
4043

4144
const formatWithOptions = ({ prefix: prefixes = [], eol = '\n', ...options }, ...args) => {
4245
const prefix = prefixes.filter(p => p != null).join(' ')
43-
const formatted = STRIP_C01(baseFormatWithOptions(options, ...args))
46+
const formatted = redactLog(STRIP_C01(baseFormatWithOptions(options, ...args)))
4447
// Splitting could be changed to only `\n` once we are sure we only emit unix newlines.
4548
// The eol param to this function will put the correct newlines in place for the returned string.
4649
const lines = formatted.split(/\r?\n/)

test/lib/utils/display.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ t.test('can log cleanly', async (t) => {
3737
const { log, logs } = await mockDisplay(t)
3838

3939
log.error('', 'test\x00message')
40+
log.info('', 'fetch DELETE 200 https://registry.npmjs.org/-/user/token/npm_000000000000000000000000000000000000 477ms')
4041
t.match(logs.error, ['test^@message'])
42+
t.match(logs.info, ['fetch DELETE 200 https://registry.npmjs.org/-/user/token/npm_*** 477ms'])
4143
})
4244

4345
t.test('can handle special eresolves', async (t) => {

0 commit comments

Comments
 (0)