Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
`audit` records security-relevant events and always emits. */

const RANK = { debug: 10, info: 20, warn: 30, error: 40 };
const THRESHOLD = { debug: 10, info: 20, warn: 30, error: 30, errors: 30 };
const THRESHOLD = { debug: 10, info: 20, warn: 30, error: 30 };
const ABBR = { debug: 'DBG', info: 'INF', warn: 'WRN', error: 'ERR', audit: 'AUD' };

let _threshold = THRESHOLD.info;
Expand Down
20 changes: 20 additions & 0 deletions api/test/log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ test('setLevel accepts known names and rejects unknown ones', () => {
assert.equal(log.setLevel('nonsense'), false);
});

/* The threshold table carried a fifth name, `errors`, that the rank table never
had: documented nowhere, offered by no UI, rejected by the settings route,
and reachable only by setting LOG_LEVEL to it by hand. */
test('the accepted level names are the four the rest of the app knows', () => {
for (const name of ['debug', 'info', 'warn', 'error']) {
assert.equal(log.setLevel(name), true, `${name} must stay accepted`);
}
assert.equal(log.setLevel('errors'), false, 'the undocumented alias is gone');
});

/* warn and error deliberately share a threshold: the Settings tip reads "Errors
shows warnings and errors only". Raising error to 40 would silently drop
warnings for every install that selected it. */
test('warnings still emit at the error level', t => {
const lines = capture(t);
log.setLevel('error');
log.warn('still here');
assert.match(lines.join(''), /msg="still here"/);
});

/* ── P1-4: values were printed bare ───────────────────────────────────────────
A value containing a newline ended the line and started another, so one
log.error call could emit a second line indistinguishable from a genuine AUD
Expand Down
Loading