Skip to content

Per-session log files with size rollover (#291) - #1108

Open
IcanBENCHurCAT wants to merge 2 commits into
C7-Game:Developmentfrom
IcanBENCHurCAT:fix/per-session-log-files
Open

IcanBENCHurCAT wants to merge 2 commits into
C7-Game:Developmentfrom
IcanBENCHurCAT:fix/per-session-log-files

Conversation

@IcanBENCHurCAT

Copy link
Copy Markdown

Closes #291

following up on the discussion in #291. the file sink stops recording once log.txt hits the 50 MB limit, and as i found digging into it there, stock serilog rolling does not fix the naming either (the plain filename ends up being the oldest chunk, not the latest).

this takes the per-session route wildweazel leaned toward:

  • each run writes to its own file, log-yyyyMMdd-HHmmss.txt, so the newest log is just the newest file
  • rollOnFileSizeLimit is on, so a long session rolls to _001, _002 etc instead of going silent at 50 MB. capped at 10 chunks per session
  • on startup, old session logs are pruned, keeping the last 10 sessions. the current session is never touched, and a leftover log.txt from before this change counts as one old session and just ages out, it is not renamed or deleted up front
  • no new packages, this is all doable with the pinned serilog 2.12 / sinks file 5.0

the grouping/pruning logic lives in C7Engine as LogFiles (pure System.IO) so it can be unit tested, C7 itself is not referenced by EngineTests. LogFilesTest covers the filename format, session grouping including rolled chunks and the legacy files, and the prune rules.

one judgement call in there: FilesPerSessionToKeep is 10, so a single session caps around 500 MB. the sink default would have been 31 chunks, close to 1.5 GB, which felt like a lot. easy to change if you want a different number.

The file sink stopped recording once log.txt hit its 50 MB limit.
Give each session its own timestamped log file, roll on size within
a session, and prune old sessions on startup keeping the last 10.
Grouping and pruning logic lives in C7Engine (LogFiles) so it is
unit tested; no new packages.
WritableDir is empty in editor runs, so LogFilePath is a bare filename and Path.GetDirectoryName returns an empty string, which PruneOldSessions treats as no directory and skips. Old session logs were never pruned in those runs (exported builds were unaffected). Resolve the full path before taking the directory, which matches where the sink writes the relative path.
@IcanBENCHurCAT

Copy link
Copy Markdown
Author

found a bug in this one while testing on windows with a real godot launch: old sessions never got pruned when running from the editor. WritableDir is empty there, so LogFilePath is a bare filename, GetDirectoryName returns an empty string, and PruneOldSessions reads that as no directory and bails. exported builds were fine and the unit tests were fine (they pass a real directory), only an actual launch caught it.

fix is in 8ddf2fc: resolve the full path before taking the directory in LogManager, so pruning sees the directory the sink actually writes to. one line plus a comment saying why.

@WildWeazel

Copy link
Copy Markdown
Member

That all sounds reasonable to me. I'm still surprised none of this was baked into Serilog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log file should rotate out when it hits its size limit, not just stop recording

2 participants