Skip to content

Commit

Permalink
fix: Do not log warnings about log cleanup when logs_max=0 (#6271)
Browse files Browse the repository at this point in the history
Closes #6270
  • Loading branch information
jmealo committed Mar 22, 2023
1 parent 2def359 commit 94d2b39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/utils/log-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ class LogFiles {
}
}
} catch (e) {
log.warn('logfile', 'error cleaning log files', e)
// Disable cleanup failure warnings when log writing is disabled
if (this.#logsMax > 0) {
log.warn('logfile', 'error cleaning log files', e)
}
} finally {
log.silly('logfile', 'done cleaning log files')
}
Expand Down
14 changes: 14 additions & 0 deletions test/lib/utils/log-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@ t.test('glob error', async t => {
t.match(last(logs).content, /error cleaning log files .* bad glob/)
})

t.test('do not log cleaning errors when logging is disabled', async t => {
const { readLogs } = await loadLogFile(t, {
logsMax: 0,
mocks: {
glob: () => {
throw new Error('should not be logged')
},
},
})

const logs = await readLogs()
t.equal(logs.length, 0)
})

t.test('cleans old style logs too', async t => {
const logsMax = 5
const oldLogs = 10
Expand Down

0 comments on commit 94d2b39

Please sign in to comment.