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.
Summary
rfl.log.setup_loggerandenforce_debugapply the samelog_flags/debug_flagsfilter 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_loggerandenforce_debug, roughly:It is not in
__all__and not reusable for handlers RFL does not create.Motivation
Consumers already reimplement this as a local
component_flag_filterso that:LoggingHandlerapplies the same allow-list as stream loggingsetup_loggerinternalsDuplicating ~15 lines is fine short-term, but semantics can drift if RFL ever changes flag rules (
ALL, first segment ofrecord.name, DEBUG vs non-DEBUG lists).Proposed API
Something like:
Requirements:
ALL, logger name first segment, DEBUG gated bydebug_flagsonly)setup_loggerandenforce_debug(single implementation)rfl.log(__all__)Exact return type (
Filtersubclass vs callable) is up to maintainers; a callable compatible withHandler.addFilteris enough.