Skip to content

Commit

Permalink
Update init_log for better integration with ovos-utils and config…
Browse files Browse the repository at this point in the history
…uration changes (#532)

* Update `init_log` to use shared logic from `ovos_utils`
Update `level_overrides` config handling to support new config structure

* Update `init_log` for backwards-compat.
Annotate remaining code in `init_log`

* Add back support for passed `config`

* Better `log_name` handling

* Fix bug in config handling

* More backwards-compat updates

---------

Co-authored-by: Daniel McKnight <[email protected]>
  • Loading branch information
NeonDaniel and NeonDaniel authored Jul 25, 2024
1 parent 04c0a5b commit b30fc11
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions neon_utils/log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,24 @@ def init_log(config: dict = None, log_name: str = None) -> type(LOG):
:param log_name: Optional LOG.name override, else use Configuration or default
:returns: LOG singleton
"""
from ovos_config.config import Configuration
_cfg = config or Configuration()
_log_level = _cfg.get("log_level", "INFO")
_logs_conf = _cfg.get("logs") or {}
_logs_conf["level"] = _log_level
LOG.name = log_name or _logs_conf.get("name") or "neon-utils"
LOG.debug(f"Initializing logger with: {_logs_conf}")
LOG.init(_logs_conf) # read log level from config
log_name = log_name or "neon-utils"
if not config:
from ovos_utils.log import init_service_logger
init_service_logger(log_name)
from ovos_config.config import Configuration
_cfg = Configuration()
else:
# TODO: This is not apparently used anywhere; consider deprecation
_cfg = config
_logs_conf = _cfg.get("logs") or {}
_logs_conf["level"] = _cfg.get("log_level", "INFO")
LOG.debug(f"Initializing logger with: {_logs_conf}")
LOG.init(_logs_conf) # read log level from config
LOG.name = _logs_conf.get('name') or log_name

_logs_conf = _cfg.get("logs") or _cfg.get("logging") or {}

# Global overrides for packages like `filelock` and `pika` which are noisy
overrides = _logs_conf.get('level_overrides') or {}
for log in overrides.get("error") or []:
logging.getLogger(log).setLevel(logging.ERROR)
Expand Down

0 comments on commit b30fc11

Please sign in to comment.