From 1d312c066b8d25aa329622d59d0f729224e36ac8 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Thu, 19 Sep 2024 13:40:37 -0500 Subject: [PATCH] feat: logger atlevel method --- src/ape/logging.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ape/logging.py b/src/ape/logging.py index fd4161c90d..309b3aa0b9 100644 --- a/src/ape/logging.py +++ b/src/ape/logging.py @@ -3,6 +3,7 @@ import sys import traceback from collections.abc import Callable, Sequence +from contextlib import contextmanager from enum import IntEnum from pathlib import Path from typing import IO, Any, Optional, Union @@ -185,6 +186,13 @@ def set_level(self, level: Union[str, int, LogLevel]): for _logger in self._extra_loggers.values(): _logger.setLevel(level) + @contextmanager + def at_level(self, level: Union[str, int, LogLevel]): + initial_level = self.level + self.set_level(level) + yield + self.set_level(initial_level) + def log_error(self, err: Exception): """ Avoids logging empty messages.