LogRecord.args not accessible
Nobody has claimed this yet.
- #810 by @SarthakB11 — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
Research direction
The report points to structlog.stdlib.ProcessorFormatter.format and shows a reproducer using ProcessorFormatter with logging.LogRecord.args. Start by reading that formatter and the related tests, then run the reproducer to confirm where args becomes empty. Done means the original arguments are accessible to the processor and a regression test covers the reported case.
Written by the indexing model from the issue text.
Description
If you inspect the stack the args are present in logging.Handler.format but not structlog.stdlib.ProcessorFormatter.format
processor, temp.py:15 <-- record.args = ()
format, stdlib.py:116 <-- record.args = ()
format, __init__.py:999 <-- record.args = ('a', 'b')
emit, __init__.py:1160
handle, __init__.py:1028
callHandlers, __init__.py:1762
handle, __init__.py:1700
_log, __init__.py:1684
info, __init__.py:1539
<module>, temp.py:26
import logging
import sys
import structlog
from structlog.types import EventDict
from structlog.typing import WrappedLogger
structlog.configure(processors=[structlog.stdlib.render_to_log_args_and_kwargs]) # processor shouldn't really matter here
def processor(logger: WrappedLogger, method_name: str, event_dict: EventDict) -> EventDict:
log_record: logging.LogRecord | None = event_dict.get("_record")
if log_record:
print(f"{log_record.args=}")
return event_dict["event"]
formatter = structlog.stdlib.ProcessorFormatter(fmt="%(message)s", processors=[processor])
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
logging.basicConfig(level=logging.INFO, handlers=[handler])
logger = logging.getLogger()
logger.info("test a=%s b=%s", "a", "b")
- Dominant language
- Python
- Stars
- 5k
- Forks
- 302
- Avg merge
- 17m
- Merged PRs (30d)
- 4
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hynek/structlog
-
bind_contextvars is not thread-safe?Possibly taken @nosmile99 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Transform examples in docs into included source filesPossibly taken @alexchen-sys claimed this 102 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
waiting for feedback
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
521xueweihan/HelloGitHub#4115 ·
-
get_lldp_neighbors_detail: query asks for 'max-address' (typo for 'mac-address'), so remote_chassis_id is always emptyPossibly taken @Jah-yee claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
lesson-submission pending-review
Difficulty 1/5 Under an hour Newbie friendliness 74/100
Ikalus1988/MisakaNet#3899 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
aws-samples/sample-per-model-bedrock#549 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100