删除库存和旧回调管理

This commit is contained in:
yml
2026-05-25 23:07:19 +08:00
parent 90ad866ecc
commit 2c7464b1eb
87 changed files with 94 additions and 5794 deletions
+5 -5
View File
@@ -28,7 +28,7 @@ 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('webhook', '2026-04-14T10:00:00.000Z'), /webhook-2026-04-14\.log$/)
assert.match(resolveLogFilePath('integration', '2026-04-14T10:00:00.000Z'), /integration-2026-04-14\.log$/)
})
test('resolveExpiredLogFilenames keeps latest seven days and ignores unknown files', () => {
@@ -37,17 +37,17 @@ test('resolveExpiredLogFilenames keeps latest seven days and ignores unknown fil
'app-2026-04-13.log',
'app-2026-04-08.log',
'app-2026-04-07.log',
'webhook-2026-04-06.log',
'integration-2026-04-06.log',
'app.log',
'webhook.log',
'integration.log',
'random.txt',
], '2026-04-14T12:00:00.000Z', 7)
assert.deepEqual(expired, [
'app-2026-04-07.log',
'webhook-2026-04-06.log',
'integration-2026-04-06.log',
'app.log',
'webhook.log',
'integration.log',
])
})
+5 -5
View File
@@ -35,7 +35,7 @@ const DATA_ROOT = resolveDataRoot()
const LOG_DIR = path.join(DATA_ROOT, 'logs')
const ACTIVE_LOG_LEVEL = normalizeLogLevel(runtimeConfig.logging?.level)
const LOG_RETENTION_DAYS = 7
const LEGACY_LOG_FILES = new Set(['app.log', 'webhook.log'])
const LEGACY_LOG_FILES = new Set(['app.log', 'integration.log'])
let writeQueue = Promise.resolve()
let lastCleanupDateKey = ''
@@ -60,8 +60,8 @@ export function logError(scope, message, detail = undefined) {
return writeLog('error', scope, message, detail)
}
export function logWebhook(scope, message, detail = undefined, { level = 'info' } = {}) {
return writeLog(level, scope, message, detail, { channel: 'webhook' })
export function logIntegration(scope, message, detail = undefined, { level = 'info' } = {}) {
return writeLog(level, scope, message, detail, { channel: 'integration' })
}
function writeLog(level, scope, message, detail, { channel = 'app' } = {}) {
@@ -167,7 +167,7 @@ export function formatLogEntry(entry, { color = false } = {}) {
}
export function resolveLogFilePath(channel = 'app', time = new Date().toISOString()) {
const normalizedChannel = String(channel || '').trim() === 'webhook' ? 'webhook' : 'app'
const normalizedChannel = String(channel || '').trim() === 'integration' ? 'integration' : 'app'
return path.join(LOG_DIR, `${normalizedChannel}-${extractLogDateKey(time)}.log`)
}
@@ -392,7 +392,7 @@ function shouldDeleteLogFileByDate(fileName, cutoffDateKey) {
return true
}
const matched = /^(app|webhook)-(\d{4}-\d{2}-\d{2})\.log$/.exec(String(fileName || '').trim())
const matched = /^(app|integration)-(\d{4}-\d{2}-\d{2})\.log$/.exec(String(fileName || '').trim())
if (!matched) {
return false