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, a logging.Handler subclass that converts each LogRecord to an oc_diagnostics._dbg() call.

  • Map Python logging levels to oc_diagnostics diagnostic levels via a configurable level_map dict.

  • 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 domain and level_map are settable at construction time.

class oc_diagnostics.logging_handler.OcDiagnosticsHandler(domain: str = 'GENERAL', level_map: dict[int, int] | None = None)[source]#

Bases: Handler

A logging.Handler that routes records through oc_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 logging level integers to oc_diagnostics diagnostic level integers. When None, 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)
emit(record: LogRecord) None[source]#

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.