From 2013f9c844a4b6234425b47d0cb78b5450da5f78 Mon Sep 17 00:00:00 2001 From: bonnal-enzo Date: Thu, 30 Nov 2023 17:53:34 +0100 Subject: [PATCH] logging: use 'kioss' LOGGER instead og root one --- kioss/__init__.py | 1 + kioss/_exec.py | 6 ++---- kioss/_plan.py | 5 ++--- kioss/_util.py | 10 ++++++++++ setup.py | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/kioss/__init__.py b/kioss/__init__.py index c7d8b50..4a4b997 100644 --- a/kioss/__init__.py +++ b/kioss/__init__.py @@ -1 +1,2 @@ from kioss._plan import SourcePipe as Pipe +from kioss._util import LOGGER diff --git a/kioss/_exec.py b/kioss/_exec.py index e8cb686..1e0512d 100644 --- a/kioss/_exec.py +++ b/kioss/_exec.py @@ -1,4 +1,3 @@ -import logging import time from datetime import datetime from typing import ( @@ -58,11 +57,10 @@ def __init__(self, iterator: Iterator[T], what: str) -> None: self.errors_count = 0 self.last_log_at_yields_count = None self.start_time = time.time() - logging.getLogger().setLevel(logging.INFO) - logging.info("iteration over '%s' will be logged.", self.what) + _util.LOGGER.info("iteration over '%s' will be logged.", self.what) def _log(self) -> None: - logging.info( + _util.LOGGER.info( "%s `%s` have been yielded in elapsed time '%s' with %s errors produced", self.yields_count, self.what, diff --git a/kioss/_plan.py b/kioss/_plan.py index eeae0e1..94c6f8c 100644 --- a/kioss/_plan.py +++ b/kioss/_plan.py @@ -1,5 +1,4 @@ import itertools -import logging from abc import ABC, abstractmethod from typing import ( Any, @@ -25,7 +24,7 @@ def __init__(self, upstream: "Optional[APipe[T]]" = None): @abstractmethod def __iter__(self) -> Iterator[T]: - raise NotImplemented() + raise NotImplemented() # TODO: Visitor pattern def __add__(self, other: "APipe[T]") -> "APipe[T]": return self.chain(other) @@ -226,7 +225,7 @@ def register_error_sample(error): n_samples=n_samples ) if errors_count > 0: - logging.error( + _util.LOGGER.error( "first %s error samples: %s\nWill now raise the first of them:", n_error_samples, list(map(repr, error_samples)), diff --git a/kioss/_util.py b/kioss/_util.py index cd584c4..a0c1d31 100644 --- a/kioss/_util.py +++ b/kioss/_util.py @@ -1,5 +1,15 @@ from typing import Any, Callable, Iterable, Iterator, Type, TypeVar, Union +import logging + +LOGGER = logging.getLogger("kioss") +handler = logging.StreamHandler() +formatter = logging.Formatter("%(asctime)s:%(name)s:%(levelname)s: %(message)s") +handler.setFormatter(formatter) +LOGGER.addHandler(handler) +LOGGER.setLevel(logging.INFO) + + T = TypeVar("T") R = TypeVar("R") diff --git a/setup.py b/setup.py index d245601..5a866fc 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='kioss', - version='0.5.1', + version='0.5.2', packages=['kioss'], url='http://github.com/bonnal-enzo/kioss', license='Apache 2.',