Skip to content

Fix spurious profiler header-mismatch warning on empty log file - #14

Merged
cboulay merged 1 commit into
devfrom
cboulay/fix-profiler-header-warning
Sep 3, 2026
Merged

Fix spurious profiler header-mismatch warning on empty log file#14
cboulay merged 1 commit into
devfrom
cboulay/fix-profiler-header-warning

Conversation

@cboulay

@cboulay cboulay commented Sep 3, 2026

Copy link
Copy Markdown
Member

Fixes #12.

_setup_logger treated an empty first line as a header mismatch, so it warned — misleadingly, about an ezmsg version mismatch — and unlinked the file on every process start. Since the header is only written at DEBUG level while logging.FileHandler creates the file eagerly, a run with profiling off leaves a zero-byte log behind, so the condition perpetuates itself forever.

  • Guard the header comparison with if not first_line, matching ezmsg/util/profiler.py.
  • Construct the handler with delay=True, so a run with profiling disabled no longer creates an empty file at all.

Tests: two regression tests — an empty log file produces no ezmsg warning and still gets the header written; profiling at INFO leaves no file on disk. The latter saves/restores the shared ezprofile logger level, since _setup_logger mutates global logging state that the existing decorator tests rely on.

Verified against the repro in the issue: the empty-file run is silent, and a fresh run with profiling disabled creates nothing. Full suite passes (210 passed, 1 skipped).

🤖 Generated with Claude Code

_setup_logger treated an empty first line as a header mismatch, so it
warned and unlinked the file on every process start. Because the header
is only written at DEBUG level while FileHandler created the file
eagerly, a run with profiling off left a zero-byte log behind, making
the condition self-perpetuating.

Guard the comparison with `if not first_line` (matching
ezmsg/util/profiler.py) and construct the handler with delay=True so no
empty file is created when nobody asked for profiling.

Fixes #12

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cboulay
cboulay merged commit d7ad85b into dev Sep 3, 2026
14 checks passed
@cboulay
cboulay deleted the cboulay/fix-profiler-header-warning branch September 3, 2026 23:18
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.

Spurious "Profiling header mismatch" warning on every process start when the profiler log is empty

1 participant