Skip to content

Convert remaining f-string logger calls to lazy form#2680

Merged
pankajastro merged 2 commits into
mainfrom
lazy-logging-multiline-followup
May 27, 2026
Merged

Convert remaining f-string logger calls to lazy form#2680
pankajastro merged 2 commits into
mainfrom
lazy-logging-multiline-followup

Conversation

@pankajastro
Copy link
Copy Markdown
Contributor

Follow-up to #2672. The original sweep caught ~47 single-line logger.X(f"...") sites but missed two patterns:

  1. Multi-line calls of the form

    logger.exception(
        f"..."
    )
    

    in cosmos/plugin/airflow3.py (three sites) and cosmos/dbt/parser/output.py (one site). The original regex required the f-string on the same line as the logger call.

  2. self.log.X(f"...") calls in operators that inherit Airflow's LoggingMixin. These never matched the original logger.X(f"...") pattern even though they violate the lazy logging rule identically. Affects azure_container_instance, docker, kubernetes, aws_ecs, gcp_cloud_run_job, and virtualenv operators.

Also converts one eager percent-interpolation call in cosmos/cache.py ("%s" % repr(e)) that used %-formatting instead of an f-string and so was outside the scope of #2672.

No behaviour change.

Follow-up to #2672. The original sweep caught ~47 single-line
logger.X(f"...") sites but missed two patterns:

1. Multi-line calls of the form

       logger.exception(
           f"..."
       )

   in cosmos/plugin/airflow3.py (three sites) and
   cosmos/dbt/parser/output.py (one site). The original regex
   required the f-string on the same line as the logger call.

2. self.log.X(f"...") calls in operators that inherit Airflow's
   LoggingMixin. These never matched the original
   logger.X(f"...") pattern even though they violate the lazy
   logging rule identically. Affects azure_container_instance,
   docker, kubernetes, aws_ecs, gcp_cloud_run_job, and
   virtualenv operators.

Also converts one eager percent-interpolation call in
cosmos/cache.py ("%s" % repr(e)) that used %-formatting
instead of an f-string and so was outside the scope of #2672.

No behaviour change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 14, 2026 15:51
@pankajastro pankajastro requested review from a team, corsettigyg, dwreeves and jbandoro as code owners May 14, 2026 15:51
@pankajastro pankajastro requested review from pankajkoti and tatiana May 14, 2026 15:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR completes the follow-up sweep to convert remaining eager log message formatting (f-strings and %-interpolation) into lazy logging calls across Cosmos, including multiline logger.exception(...) patterns and self.log.*(...) usages from Airflow LoggingMixin.

Changes:

  • Convert multiline logger.exception(f"...") calls to lazy logger.exception("...", args...) form.
  • Convert self.log.<level>(f"...") calls in several operators to lazy formatting.
  • Replace one eager string interpolation in cosmos/cache.py with lazy %r formatting.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cosmos/plugin/airflow3.py Converts multiline logger.exception(f"...") calls to lazy logging with args.
cosmos/operators/virtualenv.py Converts several self.log.info(f"...") calls to lazy logging.
cosmos/operators/kubernetes.py Converts command logging to lazy form.
cosmos/operators/gcp_cloud_run_job.py Converts command logging to lazy form.
cosmos/operators/docker.py Converts command logging to lazy form.
cosmos/operators/azure_container_instance.py Converts command logging to lazy form.
cosmos/operators/aws_ecs.py Converts command logging to lazy form.
cosmos/dbt/parser/output.py Converts an f-string error log to lazy logging with args.
cosmos/cache.py Replaces eager %-interpolation with lazy logging using %r.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cosmos/operators/virtualenv.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 14, 2026 15:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.07%. Comparing base (4867faf) to head (f0464b5).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2680      +/-   ##
==========================================
+ Coverage   98.03%   98.07%   +0.03%     
==========================================
  Files         105      105              
  Lines        7843     7843              
==========================================
+ Hits         7689     7692       +3     
+ Misses        154      151       -3     

☔ 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
Copy Markdown
Collaborator

@tatiana tatiana left a comment

Choose a reason for hiding this comment

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

@pankajastro thanks for addressing this. Please, could you adapt our CLAUDE.md or AGENTS.md to instruct agents to use logging with lazy form instead of f-string?

@tatiana tatiana self-assigned this May 27, 2026
@pankajastro
Copy link
Copy Markdown
Contributor Author

@pankajastro thanks for addressing this. Please, could you adapt our CLAUDE.md or AGENTS.md to instruct agents to use logging with lazy form instead of f-string?

We have added this claude.md in PR #2679

@pankajastro pankajastro merged commit 4521920 into main May 27, 2026
129 checks passed
@pankajastro pankajastro deleted the lazy-logging-multiline-followup branch May 27, 2026 11:12
@tatiana tatiana added this to the Cosmos 1.15.0 milestone May 28, 2026
pankajastro added a commit that referenced this pull request Jun 3, 2026
The Logging section told contributors to "get loggers via
`cosmos.log.get_logger`" unconditionally, which would lead someone
working in an operator to add a module-level `get_logger` — the exact
inconsistency #1157 set out to fix.

Scope that guidance to library/module-level code and state the operator
rule: inside operators and hooks (anything with `LoggingMixin`), log via
`self.log` so messages land in the per-task-instance log shown in the
Airflow UI. Examples updated to show both cases.

This locks in the outcome of the logging cleanup (#2670, #2680, #2681)
so it doesn't silently regress.
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.

3 participants