oc_diagnostics.logging_handler module#
Python logging Handler#
Purpose#
Bridge the Python standard-library logging module into oc_diagnostics
so that libraries and frameworks that emit log records via logging.getLogger
are automatically captured and displayed through the unified diagnostics system.
Responsibilities#
Provide
OcDiagnosticsHandler, alogging.Handlersubclass that converts eachLogRecordto anoc_diagnostics._dbg()call.Map Python logging levels to oc_diagnostics diagnostic levels via a configurable
level_mapdict.- Use a sensible default mapping:
DEBUG → L4 (deep tracing) INFO → L2 (lifecycle) WARNING → L1 (errors only) ERROR → L1 CRITICAL → L1
Diagnostics#
Domain: configurable (default: “GENERAL”) Levels: determined by level_map at runtime
Contracts#
Must not raise; errors are delegated to
logging.Handler.handleError().Requires no optional dependencies (pure Python, always available).
The
domainandlevel_mapare settable at construction time.
- class oc_diagnostics.logging_handler.OcDiagnosticsHandler(domain: str = 'GENERAL', level_map: dict[int, int] | None = None)[source]#
Bases:
HandlerA
logging.Handlerthat routes records throughoc_diagnostics._dbg().- Parameters:
domain (str) – The oc_diagnostics domain used for all records routed through this handler. Default
"GENERAL".level_map (dict[int, int] | None) – Mapping from Python
logginglevel integers to oc_diagnostics diagnostic level integers. WhenNone, the built-in default is used: DEBUG→4, INFO→2, WARNING/ERROR/CRITICAL→1.
Example
import logging from oc_diagnostics import OcDiagnosticsHandler handler = OcDiagnosticsHandler(domain="DATA") logging.getLogger("sqlalchemy").addHandler(handler)