Skip to content

313 make logger use file path and line#323

Merged
GDYendell merged 10 commits intomainfrom
313-make_logger_use_file_path_and_line
Mar 3, 2026
Merged

313 make logger use file path and line#323
GDYendell merged 10 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 source file path and line number for clearer diagnostics.
  • Breaking Changes

    • Legacy logger-binding helper removed; projects must use the provided singleton logger directly.
    • Tracer initialization simplified: no module name parameter required.
  • Documentation

    • Driver logging guidance updated to demonstrate direct singleton logger usage and simplified tracer examples.

Breaking Changes

  • bind_logger removed. Use from fastcs.logging import logger, or create a driver logger using logger.opt. See logger docstring for more information
  • Tracer no longer takes a name

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

coderabbitai bot commented Feb 17, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces per-module logger bindings and the exported bind_logger with a shared logger import from fastcs.logging; removes implicit logger configuration at import time; updates log formatting to include source path and line; and simplifies Tracer construction (no name parameter) across modules.

Changes

Cohort / File(s) Summary
Logging core
src/fastcs/logging/__init__.py, src/fastcs/logging/_logging.py
Removes bind_logger export and the implicit _configure_logger(logger) import-time call; narrows public exports. Updates format_record to add dynamic message padding and include <name> [<path>:<line>] in log lines.
Tracer
src/fastcs/tracer.py, src/fastcs/transports/epics/pva/_pv_handlers.py
Tracer.__init__ no longer accepts or stores a name; log_event stops forwarding logger_name. Module-level tracer instantiations changed from Tracer(__name__)Tracer().
Attributes
src/fastcs/attributes/attr_r.py, src/fastcs/attributes/attr_rw.py, src/fastcs/attributes/attr_w.py, src/fastcs/attributes/attribute.py
Removed local bind_logger imports/usages and module-level binding; modules now rely on the shared logger import.
Core components
src/fastcs/control_system.py, src/fastcs/controllers/base_controller.py
Replaced bind_logger import with direct logger import and removed local binding calls; tracer creation simplified where present.
Methods
src/fastcs/methods/command.py, src/fastcs/methods/scan.py
Switched from creating a bound logger at import time to importing the shared logger.
Transports (controller & EPICS)
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
Removed per-module bind_logger(...) calls; modules now use the imported singleton logger. Several files also changed tracer initialization from Tracer(name=__name__)Tracer().
Documentation & snippets
docs/snippets/static14.py, docs/snippets/static15.py, docs/tutorials/static-drivers.md
Updated examples and tutorial text to import the singleton logger and adjusted example tracer usage to Tracer(); removed guidance to use bind_logger.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code both near and far,
Swapped binds for one bright logging star,
Tracer shed its name and footprints clear,
Log lines now show where each call did steer.
A twitch, a hop — the rabbits cheer!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 summarizes the main objective: updating the logger to use file path and line number information in log output.

✏️ 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

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.74%. Comparing base (dbb85c4) to head (682ce6c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/fastcs/tracer.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #323      +/-   ##
==========================================
- Coverage   90.85%   90.74%   -0.12%     
==========================================
  Files          70       70              
  Lines        2547     2527      -20     
==========================================
- Hits         2314     2293      -21     
- Misses        233      234       +1     

☔ 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

@GDYendell GDYendell linked an issue Feb 20, 2026 that may be closed by this pull request
@JamesOHeaDLS
Copy link
Contributor Author

Updated the emphasize-lines for static14 and static15 after the edits

In child libraries this breaks because logging is partially enabled
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/fastcs/logging/_logging.py`:
- Line 93: The computed padding variable message_pad (used when formatting log
messages) can become negative for long logger names; change its calculation in
the logging routine to clamp to a non-negative value (e.g., replace the raw 100
- len(name) with a max(0, 100 - len(name))) so that downstream string formatting
(where message_pad is applied) never receives a negative width and thus avoids
ValueError; update the calculation near the code that defines message_pad and
ensure any dependent formatting uses the adjusted value.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2297a76 and 3c06731.

📒 Files selected for processing (8)
  • docs/tutorials/static-drivers.md
  • src/fastcs/control_system.py
  • src/fastcs/logging/__init__.py
  • src/fastcs/logging/_logging.py
  • src/fastcs/tracer.py
  • src/fastcs/transports/controller_api.py
  • src/fastcs/transports/epics/ca/ioc.py
  • src/fastcs/transports/epics/pva/_pv_handlers.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/fastcs/transports/epics/ca/ioc.py
  • docs/tutorials/static-drivers.md
  • src/fastcs/control_system.py

@GDYendell GDYendell force-pushed the 313-make_logger_use_file_path_and_line branch from 3c06731 to 2169b39 Compare March 3, 2026 11:00
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/fastcs/transports/controller_api.py`:
- Line 11: Remove the unused Tracer import and the module-level tracer instance:
delete the "Tracer" import (symbol Tracer) and remove the module-level
assignment "tracer = Tracer()" so no unused tracer symbol remains in
controller_api.py; ensure no other code in this module references tracer before
committing.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c06731 and 2169b39.

📒 Files selected for processing (8)
  • docs/tutorials/static-drivers.md
  • src/fastcs/control_system.py
  • src/fastcs/logging/__init__.py
  • src/fastcs/logging/_logging.py
  • src/fastcs/tracer.py
  • src/fastcs/transports/controller_api.py
  • src/fastcs/transports/epics/ca/ioc.py
  • src/fastcs/transports/epics/pva/_pv_handlers.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/fastcs/transports/epics/pva/_pv_handlers.py
  • docs/tutorials/static-drivers.md
  • src/fastcs/transports/epics/ca/ioc.py
  • src/fastcs/control_system.py

Remove bind_logger now that we report file path and line
Update Tracer for new logging
@GDYendell GDYendell force-pushed the 313-make_logger_use_file_path_and_line branch from 2169b39 to 35adfbb Compare March 3, 2026 14:11
@GDYendell GDYendell force-pushed the 313-make_logger_use_file_path_and_line branch from 1740483 to 682ce6c Compare March 3, 2026 15:00
@GDYendell GDYendell merged commit 1008960 into main Mar 3, 2026
10 of 11 checks passed
@GDYendell GDYendell deleted the 313-make_logger_use_file_path_and_line branch March 3, 2026 15:04
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.

Make logger use file path and line instead having to provide name

2 participants