Skip to content

log: export public component flag filter for custom handlers #99

Description

@rezib

Summary

rfl.log.setup_logger and enforce_debug apply the same log_flags / debug_flags filter as a private nested function. Callers that attach extra root handlers (OTLP bridges, custom stream handlers, etc.) cannot reuse that logic without copying it.

Please export a small public helper that implements the same semantics, and use it inside RFL.

Current behavior

Flag filtering is inlined in both setup_logger and enforce_debug, roughly:

def custom_filter(record):
    component = record.name.split(".")[0]
    if record.levelno == logging.DEBUG:
        if "ALL" in debug_flags or component in debug_flags:
            return 1
        return 0
    if "ALL" in log_flags or component in log_flags:
        return 1
    return 0

It is not in __all__ and not reusable for handlers RFL does not create.

Motivation

Consumers already reimplement this as a local component_flag_filter so that:

Duplicating ~15 lines is fine short-term, but semantics can drift if RFL ever changes flag rules (ALL, first segment of record.name, DEBUG vs non-DEBUG lists).

Proposed API

Something like:

def component_flag_filter(
    log_flags: list[str] | None = None,
    debug_flags: list[str] | None = None,
) -> logging.Filter | Callable[[logging.LogRecord], bool]:
    ...

Requirements:

  • Same semantics as today’s nested filter (ALL, logger name first segment, DEBUG gated by debug_flags only)
  • Used internally by setup_logger and enforce_debug (single implementation)
  • Documented and exported from rfl.log (__all__)

Exact return type (Filter subclass vs callable) is up to maintainers; a callable compatible with Handler.addFilter is enough.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions