Skip to content

Commit

Permalink
logging: use 'kioss' LOGGER instead og root one
Browse files Browse the repository at this point in the history
  • Loading branch information
ebonnal committed Nov 30, 2023
1 parent 106c51e commit 2013f9c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions kioss/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from kioss._plan import SourcePipe as Pipe
from kioss._util import LOGGER
6 changes: 2 additions & 4 deletions kioss/_exec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import time
from datetime import datetime
from typing import (
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions kioss/_plan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import logging
from abc import ABC, abstractmethod
from typing import (
Any,
Expand All @@ -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)
Expand Down Expand Up @@ -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)),
Expand Down
10 changes: 10 additions & 0 deletions kioss/_util.py
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit 2013f9c

Please sign in to comment.