refactor: consolidate log files and clean up obsolete artifacts#1597
Merged
Conversation
Fix builds for Ubuntu 22.04
Health check fix
Trim the logger from 8 file transports per version to 3:
- application-%DATE%.log: single daily-rotated JSON file at debug
level, capturing the full error/warn/info/verbose/debug stream
(the previous combined.log, application-%DATE%.log, and
debug-%DATE%.log all wrote overlapping subsets of this)
- exceptions-%DATE%.log: unhandled exceptions, daily-rotated
- rejections-%DATE%.log: unhandled promise rejections, daily-rotated
Removed transports:
- error.log (unbounded; its data was already in combined.log /
application-%DATE%.log / debug-%DATE%.log)
- combined.log (unbounded; pure duplicate of application-%DATE%.log)
- debug-%DATE%.log (superseded by application-%DATE%.log at debug
level)
- exceptions.log and rejections.log (unbounded duplicates of the
rotated siblings)
All remaining rotated transports now carry maxFiles: '30d', capping
disk usage at roughly 600 MB per logger version instead of growing
without bound.
To avoid leaving old files sitting around forever on hosts upgrading
across CADT versions, startup now deletes the superseded files from
the log directory:
error.log, combined.log, exceptions.log, rejections.log,
and debug-%DATE%.log{,.N,.gz}
Cleanup is best-effort; missing files are ignored and per-file errors
are logged rather than thrown, so a cleanup problem can never take
down startup. Journalctl / pm2 / docker continue to be the primary
real-time log consumers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1592. Reduces the on-disk logging footprint from 8 transports per logger version (16 total, counting v1 and v2) down to 3 rotated files, eliminates unbounded files, adds retention limits, and auto-cleans legacy files from hosts upgrading across CADT versions.
Context for why there were so many files:
Inspecting a real deployment's
~/.chia/mainnet/cadt/v1/logs/:error.logcombined.logapplication-*.logapplication-%DATE%.logdebug-%DATE%.logdebug-%DATE%.logexceptions.logexceptions-%DATE%.logexceptions-%DATE%.logrejections.logrejections-%DATE%.logrejections-%DATE%.logWinston 3's per-transport
levelis independent of the logger's level, sodebug-%DATE%.logwithlevel: 'debug'captured verbose/debug regardless ofAPP.LOG_LEVEL.Changes
New transport set (per logger version)
Disk usage is now bounded at ~600 MB per logger version (30 × 20 MB compressed) instead of unbounded.
Dropped transports
error.log— subset ofapplication-%DATE%.log; filter viajq '.level=="error"'orjournalctl -p errcombined.log— pure duplicatedebug-%DATE%.log— merged intoapplication-%DATE%.logat debug levelexceptions.logandrejections.log— unbounded duplicates of the rotated siblingsStartup cleanup of legacy files
New
cleanupObsoleteLogFiles(logDir)runs at logger creation and removes files superseded by rotated equivalents:error.log,combined.log,exceptions.log,rejections.log(the four unbounded files)debug-%DATE%.log,debug-%DATE%.log.N,debug-%DATE%.log.gz(matched via/^debug-.*\.log(\.\d+)?(\.gz)?\$/)Behavior guarantees:
debug-backup.tar,debug.txt,other.log) are preserved.Other adjacent concerns that this PR deliberately does NOT address (to keep diff narrow):
maxFilesconfigurable viaAPP.LOG_RETENTION_DAYS— fine with 30 as a default; can add a knob later if operators askVerification
Ran two dedicated smoke tests against
winston@3.19.0+winston-daily-rotate-file@5.0.0.Cleanup logic (seeded with the user's actual production filenames plus adversarial non-log filenames):
New application transport with logger level
info, transport leveldebug, all 6 levels emitted:sillyis correctly excluded (transport level isdebug; if operators want silly, they can setAPP.LOG_LEVEL=sillyand it will reach the journalctl Console transport from #1592 without cluttering disk).Impact on existing deployments
debug-*.log*files). All content in them is either duplicated elsewhere on disk or available in journalctl.error.logorcombined.logneed to move toapplication-*.logor to journalctl.Test plan
npm run testpasses locally~/.chia/mainnet/cadt/v1/logs/that contains the old files; verify:application-%DATE%.logat all levels error..debuginfoentry reporting the cleanup count and filenames is presentchattr +i); verify the logger still starts and emits a structured warning listing the files it couldn't removemaxFiles: '30d'behavior by advancing the system clock or manually creating older dated files and verifying they're eventually purgedNote
Medium Risk
Moderate operational risk: changes logging destinations/retention and deletes legacy log files on startup, which could affect troubleshooting workflows if misconfigured or if cleanup targets unexpected files.
Overview
Consolidates per-version file logging into a single rotated
application-%DATE%.log(capturingdebugand above) plus rotatedexceptions-%DATE%.logandrejections-%DATE%.log, and adds bounded retention viamaxFiles(30d) and shared size limits.Removes the unrotated
error.log/combined.log/exceptions.log/rejections.logtransports and adds a best-effort startup cleanup (cleanupObsoleteLogFiles) that deletes those legacy files and olddebug-*.log*artifacts, logging what was removed or failed to remove.Reviewed by Cursor Bugbot for commit 462f805. Bugbot is set up for automated code reviews on this repo. Configure here.