From d964cec5e6aa807b75c7a4e7cdc5f11e54b2eda2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 18:04:56 +0200 Subject: Adding upstream version 6.13.1. Signed-off-by: Daniel Baumann --- src/ansiblelint/logger.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/ansiblelint/logger.py (limited to 'src/ansiblelint/logger.py') diff --git a/src/ansiblelint/logger.py b/src/ansiblelint/logger.py new file mode 100644 index 0000000..18b36f4 --- /dev/null +++ b/src/ansiblelint/logger.py @@ -0,0 +1,18 @@ +"""Utils related to logging.""" +import logging +import time +from contextlib import contextmanager +from typing import Any, Iterator + +_logger = logging.getLogger(__name__) + + +@contextmanager +def timed_info(msg: Any, *args: Any) -> Iterator[None]: + """Context manager for logging slow operations, mentions duration.""" + start = time.time() + try: + yield + finally: + elapsed = time.time() - start + _logger.info(msg + " (%.2fs)", *(*args, elapsed)) -- cgit v1.2.3