From 9e2b0e7971ecd6bea7cdfe3c0f309b8682d4fb0b Mon Sep 17 00:00:00 2001 From: SandObserver <260779319+SandObserver@users.noreply.github.com> Date: Mon, 10 Aug 2026 17:31:47 -0400 Subject: [PATCH] Refactor: drop the undocumented errors log level alias The threshold table carried a fifth name the rank table never had. It appears in no documentation, no UI offers it, and the settings route validates the stored value against debug, info and error, so it was reachable only by setting LOG_LEVEL to it by hand. warn and error keep their shared threshold. The Settings tip describes that behaviour and a test pins it. --- api/src/log.js | 2 +- api/test/log.test.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/api/src/log.js b/api/src/log.js index bff2a10a..0d0d04ed 100644 --- a/api/src/log.js +++ b/api/src/log.js @@ -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; diff --git a/api/test/log.test.js b/api/test/log.test.js index 7e0405b2..4f5bc4b6 100644 --- a/api/test/log.test.js +++ b/api/test/log.test.js @@ -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