Skip to content

Commit b48958a

Browse files
committed
fix: use name of level instead of label for logging prefixes
1 parent 7f4e667 commit b48958a

2 files changed

Lines changed: 5 additions & 15 deletions

File tree

lib/utils/display.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ const LEVEL_OPTIONS = {
3838
},
3939
error: {
4040
index: 1,
41-
label: 'ERR!',
4241
},
4342
warn: {
4443
index: 2,
45-
label: 'WARN',
4644
},
4745
notice: {
4846
index: 3,
@@ -55,11 +53,9 @@ const LEVEL_OPTIONS = {
5553
},
5654
verbose: {
5755
index: 6,
58-
label: 'verb',
5956
},
6057
silly: {
6158
index: 7,
62-
label: 'sill',
6359
},
6460
}
6561

@@ -338,7 +334,7 @@ class Display {
338334
const title = args.shift()
339335
const prefix = [
340336
this.#logColors.heading(this.#heading),
341-
this.#logColors[level](levelOpts.label ?? level),
337+
this.#logColors[level](level),
342338
title ? this.#logColors.title(title) : null,
343339
]
344340
this.#stderrWrite({ prefix }, ...args)

test/fixtures/mock-logs.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
const { log: { LEVELS } } = require('proc-log')
22
const { stripVTControlCharacters: stripAnsi } = require('util')
33

4-
const labels = new Map([
5-
['error', 'ERR!'],
6-
['warn', 'WARN'],
7-
['verbose', 'verb'],
8-
['silly', 'sill'],
9-
].reduce((acc, v) => acc.concat([v, v.slice(0).reverse()]), []))
10-
const logPrefix = new RegExp(`^npm (${LEVELS.map(l => labels.get(l) ?? l).join('|')})\\s`)
4+
const logPrefix = new RegExp(`^npm (${LEVELS.join('|')})\\s`)
115
const isLog = (str) => logPrefix.test(stripAnsi(str))
126

137
// We only strip trailing newlines since some output will
@@ -63,15 +57,15 @@ module.exports = () => {
6357
// Split on spaces for the heading and level/label. We know that
6458
// none of those have spaces but could be colorized so there's no
6559
// other good way to get each of those including control chars
66-
const [rawHeading, rawLabel] = str.split(' ')
67-
const rawPrefix = `${rawHeading} ${rawLabel} `
60+
const [rawHeading, rawLevel] = str.split(' ')
61+
const rawPrefix = `${rawHeading} ${rawLevel} `
6862
// If message is colorized we can just replaceAll with the string since
6963
// it will be unique due to control chars. Otherwise we create a regex
7064
// that will only match the beginning of each line.
7165
const prefix = stripAnsi(str) !== str ? rawPrefix : new RegExp(`^${rawPrefix}`, 'gm')
7266

7367
// The level needs color stripped always because we use it to filter logs
74-
const level = labels.get(stripAnsi(rawLabel)) ?? stripAnsi(rawLabel)
68+
const level = stripAnsi(rawLevel)
7569

7670
logs.push(str.replaceAll(prefix, `${level} `))
7771
levelLogs.push({ level, message: str.replaceAll(prefix, '') })

0 commit comments

Comments
 (0)