Skip to content

fix: Minor fixes/additions to logging module.#3802

Merged
cademirch merged 11 commits intosnakemake:mainfrom
jlumpe:logging-fixes
Nov 18, 2025
Merged

fix: Minor fixes/additions to logging module.#3802
cademirch merged 11 commits intosnakemake:mainfrom
jlumpe:logging-fixes

Conversation

@jlumpe
Copy link
Copy Markdown
Contributor

@jlumpe jlumpe commented Oct 20, 2025

  • Set the initialized attribute in LoggerManager.setup().
  • Remove incorrect if statement in DefaultFilter.filter() that never matched.
  • Remove unused DefaultFormatter methods format_info() and format_d3dag().
  • Replace the get_event_level() function with get_event() as the other return value wasn't being used.
  • Correct LoggerManager.settings annotation from OutputSettingsLoggerInterface to OutputSettings (uses attributes not defined in the former).
  • Add parameter annotations to some DefaultFormatter methods.
  • Document attributes for for OutputSettings, LoggerManager, and DefaultFilter classes.

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).

Summary by CodeRabbit

  • Refactor

    • Improved internal logging/event extraction and formatting flow, with stricter type annotations for more predictable behavior and maintainability.
  • Chores

    • Expanded documentation for output settings and simplified a default setting representation for clarity.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 20, 2025

📝 Walkthrough

Walkthrough

Replaces the logging event-extraction API: get_event_level(record) -> (event, level) becomes get_event(record) -> Optional[LogEvent]. Call sites, formatting and filtering updated to use the single-event result; LoggerManager signatures and settings typing changed to "OutputSettings". OutputSettings docstring refined.

Changes

Cohort / File(s) Summary
Logging API refactoring
src/snakemake/logging.py
Replaced get_event_level() with get_event() returning Optional[LogEvent]; updated all call sites and formatting logic to handle optional event; strengthened type annotations (e.g., message payloads as dict[str, Any]); changed LoggerManager.settings typing to Optional["OutputSettings"] and LoggerManager.setup(...) signature to accept settings: "OutputSettings".
Settings documentation
src/snakemake/settings/types.py
Added/expanded docstring for OutputSettings; reformatted log_level_override default from a parenthesized annotated value with inline comment to log_level_override: Optional[int] = None (no behavior change).

Sequence Diagram(s)

sequenceDiagram
  participant Record as LogRecord
  participant GE as get_event(record)
  participant LM as LoggerManager
  participant HF as Handler(s)

  Note over Record,GE: New single-step event extraction
  Record->>GE: pass record
  GE-->>Record: Optional(LogEvent) / None
  alt Event present
    Record->>LM: format/filter using LogEvent
    LM->>HF: emit formatted message
  else No event
    Record->>LM: use record.msg / default formatting
    LM->>HF: emit formatted message
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Areas to review closely:

  • src/snakemake/logging.py — new get_event semantics and all updated call sites (formatters, filters, handlers).
  • Type changes in LoggerManager (setup signature, settings attribute) to confirm no external callers rely on the previous interface.
  • src/snakemake/settings/types.py — docstring and default change for log_level_override.

Possibly related PRs

Suggested reviewers

  • johanneskoester

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and overly broad, using generic phrasing like 'Minor fixes/additions' that doesn't convey specific information about the main changes in the changeset. Consider a more specific title that highlights the primary change, such as 'refactor: Improve logging module type annotations and documentation' or 'refactor: Simplify event extraction and fix logging issues'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description is comprehensive and mostly complete, covering all major changes with clear bullet points and addressing both QC checklist items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de9fbd1 and a192f58.

📒 Files selected for processing (1)
  • src/snakemake/settings/types.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

Files:

  • src/snakemake/settings/types.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (46)
  • GitHub Check: tests (10, windows-2022, py313)
  • GitHub Check: tests (10, ubuntu-latest, py313)
  • GitHub Check: tests (9, ubuntu-latest, py313)
  • GitHub Check: tests (8, ubuntu-latest, py313)
  • GitHub Check: tests (10, ubuntu-latest, py312)
  • GitHub Check: tests (9, windows-2022, py313)
  • GitHub Check: tests (10, ubuntu-latest, py311)
  • GitHub Check: tests (8, windows-2022, py313)
  • GitHub Check: tests (9, ubuntu-latest, py311)
  • GitHub Check: tests (9, ubuntu-latest, py312)
  • GitHub Check: tests (8, ubuntu-latest, py312)
  • GitHub Check: tests (8, ubuntu-latest, py311)
  • GitHub Check: tests (7, ubuntu-latest, py313)
  • GitHub Check: tests (6, macos-latest, py313)
  • GitHub Check: tests (7, ubuntu-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py312)
  • GitHub Check: tests (7, ubuntu-latest, py311)
  • GitHub Check: tests (7, windows-2022, py313)
  • GitHub Check: tests (7, macos-latest, py313)
  • GitHub Check: tests (6, ubuntu-latest, py311)
  • GitHub Check: tests (6, ubuntu-latest, py313)
  • GitHub Check: tests (6, windows-2022, py313)
  • GitHub Check: tests (5, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py311)
  • GitHub Check: tests (5, windows-2022, py313)
  • GitHub Check: tests (4, ubuntu-latest, py313)
  • GitHub Check: tests (5, ubuntu-latest, py313)
  • GitHub Check: tests (3, ubuntu-latest, py313)
  • GitHub Check: tests (4, ubuntu-latest, py312)
  • GitHub Check: tests (3, ubuntu-latest, py312)
  • GitHub Check: tests (4, windows-2022, py313)
  • GitHub Check: tests (4, ubuntu-latest, py311)
  • GitHub Check: tests (3, macos-latest, py313)
  • GitHub Check: tests (2, ubuntu-latest, py312)
  • GitHub Check: tests (2, ubuntu-latest, py313)
  • GitHub Check: tests (3, ubuntu-latest, py311)
  • GitHub Check: tests (3, windows-2022, py313)
  • GitHub Check: tests (2, windows-2022, py313)
  • GitHub Check: tests (2, ubuntu-latest, py311)
  • GitHub Check: tests (1, macos-latest, py313)
  • GitHub Check: tests (2, macos-latest, py313)
  • GitHub Check: tests (1, windows-2022, py313)
  • GitHub Check: tests (1, ubuntu-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py311)
  • GitHub Check: tests (1, ubuntu-latest, py313)
  • GitHub Check: apidocs
🔇 Additional comments (2)
src/snakemake/settings/types.py (2)

399-420: Good documentation addition.

The docstring clearly documents all class attributes. Note that other dataclasses in this file (e.g., ExecutionSettings, DeploymentSettings, SchedulingSettings) use "Parameters" instead of "Attributes" for their docstring sections, but both are acceptable for dataclasses.


433-434: Cleaner field definition.

Moving the inline comment to the docstring and simplifying the default value assignment improves code readability and consistency with other field definitions in the class.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jlumpe jlumpe changed the title Logging fixes Minor fixes/additions to logging module. Oct 20, 2025
@jlumpe jlumpe changed the title Minor fixes/additions to logging module. fix: Minor fixes/additions to logging module. Oct 20, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f897ff6 and de9fbd1.

📒 Files selected for processing (2)
  • src/snakemake/logging.py (16 hunks)
  • src/snakemake/settings/types.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

Files:

  • src/snakemake/logging.py
  • src/snakemake/settings/types.py
🧬 Code graph analysis (1)
src/snakemake/logging.py (2)
src/snakemake/settings/enums.py (1)
  • Quietness (24-29)
src/snakemake/settings/types.py (1)
  • OutputSettings (397-434)
🪛 Ruff (0.14.0)
src/snakemake/logging.py

162-162: Unused method argument: msg

(ARG002)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (46)
  • GitHub Check: tests (7, ubuntu-latest, py311)
  • GitHub Check: tests (10, windows-2022, py313)
  • GitHub Check: tests (9, ubuntu-latest, py313)
  • GitHub Check: tests (10, ubuntu-latest, py312)
  • GitHub Check: tests (9, ubuntu-latest, py312)
  • GitHub Check: tests (8, windows-2022, py313)
  • GitHub Check: tests (10, ubuntu-latest, py311)
  • GitHub Check: tests (9, ubuntu-latest, py311)
  • GitHub Check: tests (9, windows-2022, py313)
  • GitHub Check: tests (8, ubuntu-latest, py313)
  • GitHub Check: tests (7, macos-latest, py313)
  • GitHub Check: tests (10, ubuntu-latest, py313)
  • GitHub Check: tests (5, macos-latest, py313)
  • GitHub Check: tests (7, windows-2022, py313)
  • GitHub Check: tests (8, ubuntu-latest, py311)
  • GitHub Check: tests (7, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py313)
  • GitHub Check: tests (6, ubuntu-latest, py313)
  • GitHub Check: tests (7, ubuntu-latest, py313)
  • GitHub Check: tests (8, ubuntu-latest, py312)
  • GitHub Check: tests (6, ubuntu-latest, py311)
  • GitHub Check: tests (6, ubuntu-latest, py312)
  • GitHub Check: tests (6, windows-2022, py313)
  • GitHub Check: tests (3, macos-latest, py313)
  • GitHub Check: tests (4, ubuntu-latest, py312)
  • GitHub Check: tests (5, ubuntu-latest, py312)
  • GitHub Check: tests (4, ubuntu-latest, py313)
  • GitHub Check: tests (5, ubuntu-latest, py311)
  • GitHub Check: tests (5, windows-2022, py313)
  • GitHub Check: tests (4, ubuntu-latest, py311)
  • GitHub Check: tests (3, windows-2022, py313)
  • GitHub Check: tests (2, macos-latest, py313)
  • GitHub Check: tests (4, windows-2022, py313)
  • GitHub Check: tests (2, windows-2022, py313)
  • GitHub Check: tests (3, ubuntu-latest, py313)
  • GitHub Check: tests (2, ubuntu-latest, py313)
  • GitHub Check: tests (1, ubuntu-latest, py313)
  • GitHub Check: tests (3, ubuntu-latest, py311)
  • GitHub Check: tests (3, ubuntu-latest, py312)
  • GitHub Check: tests (1, windows-2022, py313)
  • GitHub Check: tests (2, ubuntu-latest, py312)
  • GitHub Check: tests (1, ubuntu-latest, py311)
  • GitHub Check: tests (1, macos-latest, py313)
  • GitHub Check: tests (1, ubuntu-latest, py312)
  • GitHub Check: tests (2, ubuntu-latest, py311)
  • GitHub Check: apidocs
🔇 Additional comments (12)
src/snakemake/settings/types.py (1)

398-434: LGTM! Excellent documentation addition.

The comprehensive docstring clearly documents all attributes of the OutputSettings class, improving code maintainability and developer experience.

src/snakemake/logging.py (11)

19-27: LGTM! Type annotation improvements.

The import changes correctly support the refined type annotations, with OutputSettings properly forward-referenced as a string for the TYPE_CHECKING block.


106-108: LGTM! Good API simplification.

Replacing get_event_level with get_event removes an unused return value, making the API cleaner and more focused.


132-156: LGTM! Consistent with API refactor.

The changes correctly use the simplified get_event API. The change to rd["msg"] or "" assumes the msg key is always present in the record dict (which is standard for logging.LogRecord), and the or "" handles None values appropriately.


158-219: Type annotations improve clarity.

The addition of dict[str, Any] parameter annotations to formatter methods is a good improvement for code clarity and type safety.


234-331: LGTM! Consistent type annotations.

The parameter type annotations for the helper methods are consistent with the rest of the formatter class.


334-346: LGTM! Clear documentation.

The docstring clearly documents the DefaultFilter class attributes and their purposes.


367-406: LGTM! Consistent with API refactor.

The change to use get_event(record) is correct. The level value was previously discarded, confirming it was unused.


478-508: LGTM! Correct API usage.

The change correctly uses the simplified get_event API.


530-570: LGTM! Improved documentation and type precision.

The comprehensive docstring clearly documents the LoggerManager class and its attributes. The type annotation changes from OutputSettingsLoggerInterface to "OutputSettings" correctly reflect the actual concrete type being used, improving type safety.


638-638: LGTM! Important bug fix.

Setting self.initialized = True at the end of setup() correctly marks the logger as initialized. This was missing before and is mentioned in the PR objectives as a fix.


510-527: Behavioral equivalence verified — change is correct.

The refactoring replaces get_event_level(record) with direct access to record.levelno, which is the standard Python logging API. The get_event() function now only returns the event, and the log level is accessed directly from the record object via record.levelno — functionally identical to the previous implementation while being simpler and more maintainable.

Comment thread src/snakemake/logging.py
Comment on lines +162 to 164
def format_host(self, msg: dict[str, Any]):
"""Format for host log."""
return f"host: {platform.node()}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Note: Unused parameter flagged by static analysis.

Static analysis reports that the msg parameter in format_host is unused. The method returns a static string and doesn't reference the parameter. Additionally, this method doesn't appear to be registered in the formatters dictionary (lines 142-153), suggesting it may be dead code.

Consider either:

  1. Removing the unused msg parameter if it's not needed by the method signature contract
  2. Removing the entire method if it's unused

🏁 Script executed:

#!/bin/bash
# Search for calls to format_host to verify if it's used
rg -nP '\bformat_host\b' --type=py -g '!test*'

Length of output: 76


I need to verify the formatters dictionary and check for dynamic method invocations.Let me search the codebase properly for the formatters dictionary and any dynamic invocations.

[scratchpad_update]

  • Need to examine the formatters dictionary definition to confirm if format_host is registered
  • Need to check for dynamic method calls that might invoke format_host

🏁 Script executed:

#!/bin/bash
# First, view the formatters dictionary in the logging file (lines 142-153)
echo "=== Formatters Dictionary (lines 140-160) ==="
sed -n '140,160p' src/snakemake/logging.py

echo -e "\n=== Search for dynamic method invocations (getattr, format patterns) ==="
# Look for patterns that might dynamically call formatters
rg -nP -A2 -B2 'getattr|formatters\[|format_' src/snakemake/logging.py | head -50

Length of output: 2725


Let me check for any dynamic method invocations and verify the method is truly unused:


🏁 Script executed:

#!/bin/bash
# Check the complete context around format_host and method calling patterns
echo "=== Full context around format_host (lines 158-170) ==="
sed -n '158,170p' src/snakemake/logging.py

echo -e "\n=== Search for dynamic method invocations (f-strings, format method names, etc) ==="
rg -nP 'f.*format_|getattr.*format|setattr.*format' src/snakemake/logging.py

echo -e "\n=== Check if method names are built dynamically ==="
rg -nP 'method|formatter.*=.*"' src/snakemake/logging.py | head -20

Length of output: 3206


Remove the format_host method as it is dead code.

The verification confirms the review findings: format_host is not registered in the formatters dictionary (lines 142-153) and has no callers in the codebase. The method is defined but unused, and the msg parameter is not referenced in its body. Since the method serves no purpose, it should be removed entirely rather than retained with an unused parameter.

🧰 Tools
🪛 Ruff (0.14.0)

162-162: Unused method argument: msg

(ARG002)

🤖 Prompt for AI Agents
In src/snakemake/logging.py around lines 162-164, remove the dead method
format_host(msg: dict[str, Any]) entirely: delete its definition and any unused
parameter, and ensure there are no remaining references; no other changes to
formatters dict are required since it is not registered or called anywhere.

@cademirch cademirch self-requested a review October 28, 2025 15:13
Copy link
Copy Markdown
Contributor

@cademirch cademirch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, thanks!

@cademirch cademirch merged commit 3b3986d into snakemake:main Nov 18, 2025
51 of 57 checks passed
@cademirch
Copy link
Copy Markdown
Contributor

Tests failing currently are unrelated to this PR. Think its related to cloudlflare outage today, as its happening in other repo of mine.

johanneskoester pushed a commit that referenced this pull request Nov 27, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.14.0](v9.13.7...v9.14.0)
(2025-11-27)


### Features

* Support Hy in script directive
([#3824](#3824))
([2329c9e](2329c9e))


### Bug Fixes

* Add support for pathlib in `notebook` field
([#3811](#3811))
([7b2180a](7b2180a))
* Addressed race condition in workdir_handler.py
([#3844](#3844))
([8dbfcfb](8dbfcfb))
* cleanup update-marked output files of failed jobs if there was no
backup to restore them
([#3843](#3843))
([41f1ce8](41f1ce8))
* correct Windows callable path handling
([#3832](#3832))
([5caad70](5caad70))
* expand env vars on resources
([#3823](#3823))
([fcfa1bc](fcfa1bc))
* fix backup for output marked by `update`
([#3839](#3839))
([09c64b7](09c64b7))
* Minor fixes/additions to logging module.
([#3802](#3802))
([3b3986d](3b3986d))
* mount local storage prefix into containers
([#3840](#3840))
([f1e8b62](f1e8b62))
* properly format input/output files in case of missing rule to produce
them ([#3849](#3849))
([69d5d24](69d5d24))
* Unpack AnnotatedString in _apply_wildcards
([#3798](#3798))
([7886508](7886508))


### Performance Improvements

* retrieve storage inputs immediately before scheduling jobs instead of
before running the entire workflow
([#3850](#3850))
([4ac6cda](4ac6cda))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
- Set the `initialized` attribute in `LoggerManager.setup()`.
- Remove incorrect `if` statement in `DefaultFilter.filter()` that never
matched.
- Remove unused `DefaultFormatter` methods `format_info()` and
`format_d3dag()`.
- Replace the `get_event_level()` function with `get_event()` as the
other return value wasn't being used.
- Correct `LoggerManager.settings` annotation from
`OutputSettingsLoggerInterface` to `OutputSettings` (uses attributes not
defined in the former).
- Add parameter annotations to some `DefaultFormatter` methods.
- Document attributes for for `OutputSettings`, `LoggerManager`, and
`DefaultFilter` classes.

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Improved internal logging/event extraction and formatting flow, with
stricter type annotations for more predictable behavior and
maintainability.

* **Chores**
* Expanded documentation for output settings and simplified a default
setting representation for clarity.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cade Mirchandani <[email protected]>
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.14.0](snakemake/snakemake@v9.13.7...v9.14.0)
(2025-11-27)


### Features

* Support Hy in script directive
([snakemake#3824](snakemake#3824))
([2329c9e](snakemake@2329c9e))


### Bug Fixes

* Add support for pathlib in `notebook` field
([snakemake#3811](snakemake#3811))
([7b2180a](snakemake@7b2180a))
* Addressed race condition in workdir_handler.py
([snakemake#3844](snakemake#3844))
([8dbfcfb](snakemake@8dbfcfb))
* cleanup update-marked output files of failed jobs if there was no
backup to restore them
([snakemake#3843](snakemake#3843))
([41f1ce8](snakemake@41f1ce8))
* correct Windows callable path handling
([snakemake#3832](snakemake#3832))
([5caad70](snakemake@5caad70))
* expand env vars on resources
([snakemake#3823](snakemake#3823))
([fcfa1bc](snakemake@fcfa1bc))
* fix backup for output marked by `update`
([snakemake#3839](snakemake#3839))
([09c64b7](snakemake@09c64b7))
* Minor fixes/additions to logging module.
([snakemake#3802](snakemake#3802))
([3b3986d](snakemake@3b3986d))
* mount local storage prefix into containers
([snakemake#3840](snakemake#3840))
([f1e8b62](snakemake@f1e8b62))
* properly format input/output files in case of missing rule to produce
them ([snakemake#3849](snakemake#3849))
([69d5d24](snakemake@69d5d24))
* Unpack AnnotatedString in _apply_wildcards
([snakemake#3798](snakemake#3798))
([7886508](snakemake@7886508))


### Performance Improvements

* retrieve storage inputs immediately before scheduling jobs instead of
before running the entire workflow
([snakemake#3850](snakemake#3850))
([4ac6cda](snakemake@4ac6cda))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@jlumpe jlumpe deleted the logging-fixes branch January 8, 2026 07:43
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.

2 participants