Skip to content

Commit 94d2b39

Browse files
authored
fix: Do not log warnings about log cleanup when logs_max=0 (#6271)
Closes #6270
1 parent 2def359 commit 94d2b39

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/utils/log-file.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ class LogFiles {
223223
}
224224
}
225225
} catch (e) {
226-
log.warn('logfile', 'error cleaning log files', e)
226+
// Disable cleanup failure warnings when log writing is disabled
227+
if (this.#logsMax > 0) {
228+
log.warn('logfile', 'error cleaning log files', e)
229+
}
227230
} finally {
228231
log.silly('logfile', 'done cleaning log files')
229232
}

test/lib/utils/log-file.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,20 @@ t.test('glob error', async t => {
255255
t.match(last(logs).content, /error cleaning log files .* bad glob/)
256256
})
257257

258+
t.test('do not log cleaning errors when logging is disabled', async t => {
259+
const { readLogs } = await loadLogFile(t, {
260+
logsMax: 0,
261+
mocks: {
262+
glob: () => {
263+
throw new Error('should not be logged')
264+
},
265+
},
266+
})
267+
268+
const logs = await readLogs()
269+
t.equal(logs.length, 0)
270+
})
271+
258272
t.test('cleans old style logs too', async t => {
259273
const logsMax = 5
260274
const oldLogs = 10

0 commit comments

Comments
 (0)