# -*- coding: utf-8 -*- # SPDX-License-Identifier: MIT """ Logging functions. At the beginning of the MBS flow, init_logging(conf) must be called. After that, logging from any module is possible using Python's "logging" module as showed at . Examples: import logging logging.debug("Phasers are set to stun.") logging.info("%s tried to build something", username) logging.warning("%s failed to build", task_id) """ from __future__ import absolute_import import os import logging import logging.handlers import inspect levels = { "debug": logging.DEBUG, "error": logging.ERROR, "warning": logging.WARNING, "info": logging.INFO, } level_flags = { "debug": levels["debug"], "verbose": levels["info"], "quiet": levels["error"], } log_format = "%(asctime)s - %(threadName)s - %(name)s - %(levelname)s - %(message)s" class ModuleBuildFileHandler(logging.FileHandler): """ FileHandler subclass which handles only messages generated during particular module build with `build_id` set in its constructor. """ def __init__(self, build_id, filename, mode="a", encoding=None, delay=0): logging.FileHandler.__init__(self, filename, mode, encoding, delay) self.build_id = build_id def emit(self, record): # Imported here because of importing cycle between __init__.py, # scheduler and models. from module_build_service.scheduler.consumer import MBSConsumer # Check the currently handled module build and emit the message only # if it's associated with current module. build_id = MBSConsumer.current_module_build_id if not build_id or build_id != self.build_id: return logging.FileHandler.emit(self, record) def _is_solv_object(o): """ Returns true if the object is a libsolv object or contains one. (Contains is implemented pragmatically and might need to be extended) """ if isinstance(o, (tuple, list)): return any(_is_solv_object(x) for x in o) else: return str(type(o)).startswith("