Skip to content

Fix: missing record.task_id for descendant loggers (e.g. karton.<identity>.module)#311

Merged
psrok1 merged 1 commit intomasterfrom
fix/logging-task-id-handler
Sep 11, 2025
Merged

Fix: missing record.task_id for descendant loggers (e.g. karton.<identity>.module)#311
psrok1 merged 1 commit intomasterfrom
fix/logging-task-id-handler

Conversation

@psrok1
Copy link
Member

@psrok1 psrok1 commented Sep 10, 2025

When we try to use a logger that is descendant to the karton.<identity> logger (e.g. karton.identity.something), we may get the following error:

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.12/logging/__init__.py", line 464, in format
    return self._format(record)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/logging/__init__.py", line 460, in _format
    return self._fmt % values
           ~~~~~~~~~~^~~~~~~~
KeyError: 'task_id'

That's because logging.Filter doesn't propagate and when it's attached to logger, it applies only to that logger.

If Formatter depends on context set by Filter, Filter should be applied to the Handler using that Formatter instead of Logger.

Copy link
Member

@msm-cert msm-cert left a comment

Choose a reason for hiding this comment

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

Makes sense

@psrok1 psrok1 merged commit 9a3208d into master Sep 11, 2025
7 checks passed
@psrok1 psrok1 deleted the fix/logging-task-id-handler branch September 11, 2025 13:50
@psrok1 psrok1 mentioned this pull request Sep 11, 2025
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