Skip to content

docs: document self.log vs get_logger logging convention#2764

Open
pankajastro wants to merge 2 commits into
mainfrom
docs/operator-logging-convention
Open

docs: document self.log vs get_logger logging convention#2764
pankajastro wants to merge 2 commits into
mainfrom
docs/operator-logging-convention

Conversation

@pankajastro
Copy link
Copy Markdown
Contributor

Summary

The "Python Coding Standards → Logging" section in AGENTS.md told
contributors to "get loggers via cosmos.log.get_logger"
unconditionally. Read literally, that guides someone working in an
operator to add a module-level get_logger — the exact inconsistency
#1157 set
out to fix.

This scopes that guidance to library / module-level code and states the
operator rule explicitly: 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. The Yes/No examples now
show both cases.

Why

The logging cleanup PRs (#2670, #2680, #2681) established two
conventions in code but only one was written down:

  • cosmos.log.get_logger for library code — already documented ✅
  • lazy logging — already documented ✅
  • self.log inside operators/hooks — not documented ❌ (this PR)

Capturing it keeps human contributors and AI agents (Cursor, Copilot,
Claude) from re-introducing the workaround #1157 removed.

Docs-only; one-paragraph + example change to AGENTS.md.

Related

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.
Copilot AI review requested due to automatic review settings June 3, 2026 15:58
@pankajastro pankajastro requested review from a team, corsettigyg, dwreeves and jbandoro as code owners June 3, 2026 15:58
@pankajastro pankajastro requested review from pankajkoti and tatiana June 3, 2026 15:58
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

Updates contributor documentation in AGENTS.md to clarify the logging convention difference between library/module code and operator code, aiming to prevent reintroducing inconsistent logger usage in Airflow operators.

Changes:

  • Refines the “Python Coding Standards → Logging” guidance to distinguish module-level logging from operator logging.
  • Updates the Yes/No examples to reflect both patterns.

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

Comment thread AGENTS.md Outdated
Comment thread AGENTS.md Outdated
Address review feedback on the logging convention docs:

- Scope the `self.log` guidance to operators only. The sole Cosmos hook
  (`cosmos/hooks/subprocess.py`) logs via a module-level `get_logger`,
  so "operators and hooks" misrepresented the current convention; #1157
  was about operators.
- Make the examples valid in isolation: keep the `get_logger` vs stdlib
  blocks self-contained, and show `self.log` inside a `def execute`
  method so `self` is defined rather than dangling at module level.
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