docs: document self.log vs get_logger logging convention#2764
Open
pankajastro wants to merge 2 commits into
Open
docs: document self.log vs get_logger logging convention#2764pankajastro wants to merge 2 commits into
self.log vs get_logger logging convention#2764pankajastro wants to merge 2 commits into
Conversation
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.
Contributor
There was a problem hiding this comment.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The "Python Coding Standards → Logging" section in
AGENTS.mdtoldcontributors 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 viaself.logso messages land in theper-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_loggerfor library code — already documented ✅self.loginside 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
cosmos.log.get_loggerconsistently #2670, Convert remaining f-string logger calls to lazy form #2680, Unify operator logging on self.log #2681 (logging cleanup) and Document lazy-logging standard + consistent in CLAUDE.md #2679 (logging docs)