优化日志切分和保留策略

This commit is contained in:
yml
2026-05-28 12:32:13 +08:00
parent 26d40a2c13
commit e4c9873c8d
10 changed files with 99 additions and 22 deletions
+27 -12
View File
@@ -27,27 +27,42 @@ test('shouldWriteLog respects configured minimum log level', () => {
})
test('resolveLogFilePath uses daily log file names by channel', () => {
assert.match(resolveLogFilePath('app', '2026-04-14T10:00:00.000Z'), /app-2026-04-14\.log$/)
assert.match(resolveLogFilePath('integration', '2026-04-14T10:00:00.000Z'), /integration-2026-04-14\.log$/)
assert.match(resolveLogFilePath('app', '2026-05-28T00:00:19.194+08:00'), /app-2026-05-28\.log$/)
assert.match(resolveLogFilePath('integration', '2026-05-28T00:00:19.194+08:00'), /integration-2026-05-28\.log$/)
})
test('resolveExpiredLogFilenames keeps latest seven days and ignores unknown files', () => {
test('resolveLogFilePath uses local date for utc timestamps', () => {
assert.match(resolveLogFilePath('app', '2026-05-27T16:00:19.194Z'), /app-2026-05-28\.log$/)
})
test('resolveExpiredLogFilenames keeps latest thirty days by default and ignores unknown files', () => {
const expired = resolveExpiredLogFilenames([
'app-2026-04-14.log',
'app-2026-04-13.log',
'app-2026-04-08.log',
'app-2026-04-07.log',
'integration-2026-04-06.log',
'app-2026-05-30.log',
'app-2026-05-01.log',
'app-2026-04-30.log',
'integration-2026-04-29.log',
'app.log',
'integration.log',
'random.txt',
], '2026-04-14T12:00:00.000Z', 7)
], '2026-05-30')
assert.deepEqual(expired, [
'app-2026-04-30.log',
'integration-2026-04-29.log',
'app.log',
'integration.log',
])
})
test('resolveExpiredLogFilenames supports explicit retention days', () => {
const expired = resolveExpiredLogFilenames([
'app-2026-04-14.log',
'app-2026-04-08.log',
'app-2026-04-07.log',
], '2026-04-14', 7)
assert.deepEqual(expired, [
'app-2026-04-07.log',
'integration-2026-04-06.log',
'app.log',
'integration.log',
])
})