feat(logger): add file transport with daily rotation and size cap

Adds a hand-rolled FileTransport that fans out every log line (debug
and up, regardless of console filter) to
./logs/snowluma-YYYY-MM-DD.log. When the current file exceeds the
configurable size cap it rolls into snowluma-YYYY-MM-DD.1.log, and
files older than the retention window are unlinked at startup and on
each day rollover.

Config (all env, no settings.json):
- SNOWLUMA_LOG_FILE      0 to disable file output (default: on)
- SNOWLUMA_LOG_DIR       output directory       (default: ./logs)
- SNOWLUMA_LOG_MAX_MB    per-file cap, MB       (default: 50)
- SNOWLUMA_LOG_RETAIN_DAYS retention window     (default: 7)

closeLogger() awaits the WriteStream's finish event; SIGINT and
SIGTERM handlers now await it before process.exit so the buffer
makes it to disk.

vitest config sets SNOWLUMA_LOG_FILE=0 to keep the suite from
polluting cwd; the new tests under tests/log-file-transport.test.ts
flip it back on per-test against a tmpdir.
This commit is contained in:
DrSmoothl committed 2026-05-18 00:44:30 +08:00
1 parent c6f4d5c5a2
commit 51f46e15fd
5 files changed
+445 -18

No files matched your search

+8 -1
View File
@@ -12,6 +12,13 @@ export default defineConfig({
},
test: {
include: ['tests/**/*.test.ts'],
environment: 'node'
environment: 'node',
// Suppress the logger's file transport during tests so the suite
// doesn't litter cwd with logs/snowluma-*.log files. Tests that
// explicitly cover file output set their own SNOWLUMA_LOG_FILE='1'
// + SNOWLUMA_LOG_DIR=<tmp>.
env: {
SNOWLUMA_LOG_FILE: '0'
}
}
});