From a81fde18280ef6ea5dccfaa1b98806e284d62a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Poche=C4=87?= Date: Fri, 15 Sep 2023 09:48:47 +0200 Subject: [PATCH] Move logging from root logger Logging to root logger is a bad practice - in order to allow customisation, a uniquely named logger should be used. This commit introduces standard way of logging by using __name__ as logger name. --- entsoe/decorators.py | 6 ++++-- entsoe/entsoe.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/entsoe/decorators.py b/entsoe/decorators.py index 78c017b..1cfeeb1 100644 --- a/entsoe/decorators.py +++ b/entsoe/decorators.py @@ -9,6 +9,8 @@ from .misc import year_blocks, day_blocks +logger = logging.getLogger(__name__) + def retry(func): """Catches connection errors, waits and retries""" @@ -63,7 +65,7 @@ def documents_wrapper(*args, **kwargs): frame = func(*args, offset=offset, **kwargs) frames.append(frame) except NoMatchingDataError: - logging.debug(f"NoMatchingDataError: for offset {offset}") + logger.debug(f"NoMatchingDataError: for offset {offset}") break if len(frames) == 0: @@ -97,7 +99,7 @@ def year_wrapper(*args, start=None, end=None, **kwargs): try: frame = func(*args, start=_start, end=_end, **kwargs) except NoMatchingDataError: - logging.debug(f"NoMatchingDataError: between {_start} and {_end}") + logger.debug(f"NoMatchingDataError: between {_start} and {_end}") frame = None frames.append(frame) diff --git a/entsoe/entsoe.py b/entsoe/entsoe.py index 7acc00e..67919f5 100644 --- a/entsoe/entsoe.py +++ b/entsoe/entsoe.py @@ -19,6 +19,7 @@ from .decorators import retry, paginated, year_limited, day_limited, documents_limited import warnings +logger = logging.getLogger(__name__) warnings.filterwarnings('ignore', category=XMLParsedAsHTMLWarning) __title__ = "entsoe-py" @@ -91,7 +92,7 @@ def _base_request(self, params: Dict, start: pd.Timestamp, } params.update(base_params) - logging.debug(f'Performing request to {URL} with params {params}') + logger.debug(f'Performing request to {URL} with params {params}') response = self.session.get(url=URL, params=params, proxies=self.proxies, timeout=self.timeout) try: