Feature request: Evaluate a processor chain at a given set of log levels
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 42/100
Research direction
The issue describes a ProcessAtLogLevels processor and shows how it would wrap CallsiteParameterAdder, but it does not name implementation or test files. Read the processor documentation and existing processor tests to find where a chain wrapper fits. Done means processors run only for the selected levels and the behavior is covered by tests; the issue has had no comment for 796 days, so expect little guidance.
Written by the indexing model from the issue text.
Description
I find myself only wanting certain fields included in my logging at a few select log levels. Something like:
class ProcessAtLogLevels:
"""Evaluate a chain of processors at a given set log levels.
Args:
levels: Log levels at which to evaluate processor chain.
processors: A chain of *structlog* processors that is used to process entries at the given log levels.
"""
def __init__(self, levels: int | Collection[int], *, processors: Sequence[Processor] = ()):
self._levels = levels if isinstance(levels, Collection) else (levels,)
self._processors = processors
def __call__(self, logger: WrappedLogger, method_name: str, event_dict: EventDict) -> EventDict:
if structlog.processors.NAME_TO_LEVEL[method_name] in self._levels:
for processor in self._processors:
event_dict = processor(logger, method_name, event_dict)
return event_dict
I'll end up with something like this in my processor chain:
ProcessAtLogLevels(
{logging.DEBUG, logging.CRITICAL},
processors=(
structlog.processors.CallsiteParameterAdder(
(structlog.processors.CallsiteParameter.LINENO, structlog.processors.CallsiteParameter.PATHNAME)
),
),
)
This will only add line numbers and pathname at the DEBUG and CRITICAL log levels.
- 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
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Transform examples in docs into included source filesPossibly taken @alexchen-sys claimed this 97 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
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
yunaremaia/proto-drift#22 ·
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
yunaremaia/memwatch#96 ·
-
bug good first issue
Difficulty 1/5 Under an hour Newbie friendliness 91/100
yunaremaia/ci-gate-watch#34 ·
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
yunaremaia/agent-capability-attestation#64 ·
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 1/5 Under an hour Newbie friendliness 86/100
yunaremaia/agent-call-graph#43 ·
Maintainers usually reply within 1 day