oizom_logger¶
Structured logging framework for Oizom IoT edge devices.
Provides a centralized, configurable logging stack with context-based filtering, timezone-aware timestamps, ANSI color output, and safe rotating file handlers used by every module in the Oizom hardware codebase.
The logging pipeline is built from composable components that can be used
independently or combined through the OizomLogger public wrapper:
LoggerConfig– immutable dataclass holding all configurationContextFilter– injects a context token (e.g."INIT","READ") into everylogging.LogRecordfor easy grep-based filtering of logs.StructuredFormatter– pipe-delimited format with optional timezone conversion and country indicators (emoji or code).ColorFormatter– ANSI color wrapper that respectsNO_COLORandFORCE_COLORenvironment variables plus TTY detection.SafeRotatingFileHandler– rotation that tolerates missing backup files and transientOSErroron rename/remove.OizomLogger– public API combining all of the above.
Example
Create a logger and emit a context-tagged message:
from utils.oizom_logger import OizomLogger
context_logger = OizomLogger(__name__)
context_logger.info_with_context("INIT", "Sensor setup complete")
basic_logger = OizomLogger(__name__).get()
basic_logger.info("Standard log message")
Note
This module is imported by nearly every file in the codebase. It must
remain free of circular imports – in particular it must not import
from Sensor, Manager, or any OzWrapper module.
Classes¶
High-level logger wrapper backed by |
Functions¶
|
Re-apply a configuration dictionary to every existing logger. |
Module Contents¶
- oizom_logger.apply_logger_config(config_dict: dict[str, Any]) None¶
Re-apply a configuration dictionary to every existing logger.
Walks
logging.Logger.manager.loggerDict, rebuilding the handler stack of any logger that already has at least one handler attached (i.e. has been configured throughOizomLogger). Useful for honouring runtime configuration reloads (e.g. when the operator updateslogger_config.jsonon the device).- Parameters:
config_dict – Mapping accepted by
LoggerConfig.from_dict(); the same options used atOizomLoggerconstruction time.- Returns:
None.
- Raises:
OSError – Propagated from
_build_file_handler()if the new log path cannot be opened.
Example
>>> apply_logger_config({"console_level": "WARNING"})
Note
Loggers that have never been touched (no handlers) are skipped to avoid materializing accidental noise from imported modules.