Skip to content

313 make logger use file path and line#323

Open
JamesOHeaDLS wants to merge 5 commits intomainfrom
313-make_logger_use_file_path_and_line
Open

313 make logger use file path and line#323
JamesOHeaDLS wants to merge 5 commits intomainfrom
313-make_logger_use_file_path_and_line

Conversation

@JamesOHeaDLS
Copy link
Contributor

@JamesOHeaDLS JamesOHeaDLS commented Feb 17, 2026

This address #313

Made use of file path and line number in the format record string, then purged the files of bind_logger. Where logging is used in the file, ensured that logger is imported instead of bind_logger

Summary by CodeRabbit

  • New Features

    • Log lines now include file path and line number for improved debugging.
  • Breaking Changes

    • The previous logger-binding helper was removed; code should import and use the singleton logger directly.
  • Documentation

    • Driver logging guidance updated to reflect the direct singleton logger usage.

@JamesOHeaDLS JamesOHeaDLS self-assigned this Feb 17, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

Refactors logging to stop creating per-module bound loggers via bind_logger() and instead import a pre-configured singleton logger from fastcs.logging. Also removes bind_logger() from the logging API and updates log formatting to include file:line information and remove message truncation.

Changes

Cohort / File(s) Summary
Logging core
src/fastcs/logging/__init__.py, src/fastcs/logging/_logging.py
Removes bind_logger() export; import-only of the singleton logger. Updates log formatting to append [path:line] and stop truncating messages.
Attributes
src/fastcs/attributes/attr_r.py, src/fastcs/attributes/attr_rw.py, src/fastcs/attributes/attr_w.py, src/fastcs/attributes/attribute.py
Replaces local bind_logger usage with direct import of the shared logger; removes module-level binding calls.
Core components
src/fastcs/control_system.py, src/fastcs/controllers/base_controller.py
Swaps bind_logger import for direct logger import and deletes local binding assignment.
Transports (EPICS & controller API)
src/fastcs/transports/controller_api.py, src/fastcs/transports/epics/ca/ioc.py, src/fastcs/transports/epics/ca/transport.py, src/fastcs/transports/epics/gui.py, src/fastcs/transports/epics/pva/transport.py
Removes per-module logger binding; use imported singleton logger instead.
Methods
src/fastcs/methods/command.py, src/fastcs/methods/scan.py
Replaces bound-logger creation with direct import of the shared logger.
Documentation & snippets
docs/snippets/static14.py, docs/snippets/static15.py, docs/tutorials/static-drivers.md
Updates examples and guidance to import the singleton logger instead of calling bind_logger(); adjusts example highlights.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through modules, keen and sly,
Swapped binds for one bright logger sky.
File:line now joins each track,
No truncation pulling logs back.
A tidy hop — logs unified! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: updating the logger to use file path and line information, which is confirmed by the removal of bind_logger throughout and the logging format changes in _logging.py.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 313-make_logger_use_file_path_and_line

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.

@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.77%. Comparing base (5d6b41c) to head (ac93aa0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #323      +/-   ##
==========================================
- Coverage   90.84%   90.77%   -0.07%     
==========================================
  Files          70       70              
  Lines        2555     2537      -18     
==========================================
- Hits         2321     2303      -18     
  Misses        234      234              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/tutorials/static-drivers.md (1)

420-421: ⚠️ Potential issue | 🟡 Minor

Fix out-of-range emphasize-lines spec — line 123 exceeds file length.

The Sphinx warning is valid: /snippets/static14.py has only 121 lines, but the emphasize-lines spec includes line 123, which is out of range. Line 116 is valid. Update the spec to remove line 123 or replace it with a valid line number ≤ 121.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/tutorials/static-drivers.md` around lines 420 - 421, The literalinclude
directive for the static14.py snippet has an out-of-range entry in its
emphasize-lines list; edit the emphasize-lines attribute in the literalinclude
block to remove the invalid entry (the trailing/last emphasized item) or replace
it with a valid line number within the snippet’s actual length so all emphasized
lines fall inside static14.py’s range.
🧹 Nitpick comments (1)
src/fastcs/transports/epics/ca/ioc.py (1)

259-262: Inconsistent use of print instead of logger.warning.

The analogous check for attribute PV name length (line 148) uses logger.warning(...), but this command PV check uses print(...). Consider aligning them for consistent observability.

♻️ Suggested fix
-                print(
-                    f"Not creating PV for {attr_name} as full name would exceed"
-                    f" {EPICS_MAX_NAME_LENGTH} characters"
-                )
+                logger.warning(
+                    f"Not creating PV for {attr_name} as full name would exceed"
+                    f" {EPICS_MAX_NAME_LENGTH} characters"
+                )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fastcs/transports/epics/ca/ioc.py` around lines 259 - 262, The code
prints a warning using print(...) when the command PV full name would exceed
EPICS_MAX_NAME_LENGTH; replace that print with the module logger
(logger.warning(...)) to match the earlier attribute PV check and maintain
consistent observability, using the same or equivalent message string and
including attr_name and EPICS_MAX_NAME_LENGTH; ensure you reference the same
logger instance used elsewhere in this module so the log goes to the configured
logger instead of stdout.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@docs/tutorials/static-drivers.md`:
- Around line 420-421: The literalinclude directive for the static14.py snippet
has an out-of-range entry in its emphasize-lines list; edit the emphasize-lines
attribute in the literalinclude block to remove the invalid entry (the
trailing/last emphasized item) or replace it with a valid line number within the
snippet’s actual length so all emphasized lines fall inside static14.py’s range.

---

Nitpick comments:
In `@src/fastcs/transports/epics/ca/ioc.py`:
- Around line 259-262: The code prints a warning using print(...) when the
command PV full name would exceed EPICS_MAX_NAME_LENGTH; replace that print with
the module logger (logger.warning(...)) to match the earlier attribute PV check
and maintain consistent observability, using the same or equivalent message
string and including attr_name and EPICS_MAX_NAME_LENGTH; ensure you reference
the same logger instance used elsewhere in this module so the log goes to the
configured logger instead of stdout.

CI was failing the sphinx build as an emphasized line didn't exist anymore after the changes to logging
Copy link

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
docs/tutorials/static-drivers.md (3)

451-452: ⚠️ Potential issue | 🟡 Minor

Fix unmatched backtick and sentence wrap.
The inline code for power is missing a closing backtick, which breaks formatting.

✅ Suggested fix
-Enable tracing on the `power` attribute by calling `enable_tracing` and then enable a
-ramp so that the value updates. Check the console to see the messages.  Call `disable_tracing` to disable the log messages for `power.
+Enable tracing on the `power` attribute by calling `enable_tracing` and then enable a
+ramp so that the value updates. Check the console to see the messages. Call `disable_tracing` to disable the log messages for `power`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/tutorials/static-drivers.md` around lines 451 - 452, The documentation
line misses a closing backtick for the inline code `power` and has a sentence
wrap issue; update the sentence to close the inline code (e.g., `power`) and
ensure the sentence reads smoothly—call enable_tracing and then enable a ramp so
the value updates, check the console for messages, and call disable_tracing to
stop logging for `power`—referencing the symbols enable_tracing,
disable_tracing, and the power attribute to locate and correct the text.

434-435: ⚠️ Potential issue | 🟡 Minor

Fix grammar in Tracer description.
“adds a enables” reads as a typo and is confusing.

Suggested edit: “This adds a TRACE level that is disabled by default, but can be enabled at runtime.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/tutorials/static-drivers.md` around lines 434 - 435, Fix the grammatical
typo in the Tracer description sentence by replacing "This adds a  enables
logging `TRACE` level log messages that are disabled by default, but can be
enabled at runtime." with the suggested clearer wording; update the sentence in
the Tracer/AttributeIO documentation to read: "This adds a `TRACE` level that is
disabled by default, but can be enabled at runtime." Ensure the change is
applied to the Tracer description near the mention of AttributeIO.

472-475: ⚠️ Potential issue | 🟡 Minor

Fix subject–verb agreement.
“These log messages includes” should be “include.”

Suggested edit: “These log messages include other trace loggers…”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/tutorials/static-drivers.md` around lines 472 - 475, Change the
incorrect verb form "includes" to "include" in the sentence that begins "These
log messages includes other trace loggers..." so it reads "These log messages
include other trace loggers..." (update the phrase "These log messages includes
other trace loggers that log messages with `power` as the `topic`" to use
"include").
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@docs/tutorials/static-drivers.md`:
- Around line 451-452: The documentation line misses a closing backtick for the
inline code `power` and has a sentence wrap issue; update the sentence to close
the inline code (e.g., `power`) and ensure the sentence reads smoothly—call
enable_tracing and then enable a ramp so the value updates, check the console
for messages, and call disable_tracing to stop logging for `power`—referencing
the symbols enable_tracing, disable_tracing, and the power attribute to locate
and correct the text.
- Around line 434-435: Fix the grammatical typo in the Tracer description
sentence by replacing "This adds a  enables logging `TRACE` level log messages
that are disabled by default, but can be enabled at runtime." with the suggested
clearer wording; update the sentence in the Tracer/AttributeIO documentation to
read: "This adds a `TRACE` level that is disabled by default, but can be enabled
at runtime." Ensure the change is applied to the Tracer description near the
mention of AttributeIO.
- Around line 472-475: Change the incorrect verb form "includes" to "include" in
the sentence that begins "These log messages includes other trace loggers..." so
it reads "These log messages include other trace loggers..." (update the phrase
"These log messages includes other trace loggers that log messages with `power`
as the `topic`" to use "include").

Copy link
Contributor

@GDYendell GDYendell left a comment

Choose a reason for hiding this comment

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

I think all of the highlighted lines in the snippets are going to be wrong because of this change. That can be tested by serving the docs locally with tox -e docs-autobuild

<level>[{time} {record["level"].name[0]}]</level> \
{record["message"]:<80} \
{record["message"]} \
{f"[{record['file'].path}:{record['line']}]":<80} \
Copy link
Contributor

Choose a reason for hiding this comment

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

The padding (:<80) should be on the message, not the file path / line.

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