# This file is adapted from the haggis library, available at # https://github.com/madphysicist/haggis # # The haggis library is licensed under the # GNU Affero General Public License v3.0 (AGPLv3) # # The code has been adapted since only a small code piece is needed # to avoid introducing an additional install-dependency when # using PyTeX # # You should have received a copy of the AGPLv3 license along with the # PyTeX distribution. If not, refer to # https://www.gnu.org/licenses/agpl-3.0.en.html # import logging def add_logging_level(level_name: str, level_num: int): def log_for_level(self, message, *args, **kwargs): if self.isEnabledFor(level_num): self._log(level_num, message, args, **kwargs) def log_to_root(message, *args, **kwargs): logging.log(level_num, message, *args, **kwargs) logging.addLevelName(level_num, level_name.upper()) setattr(logging, level_name.upper(), level_num) setattr(logging.getLoggerClass(), level_name.lower(), log_for_level) setattr(logging, level_name.lower(), log_to_root)