From fe7e09207e7fb3db5c707d1f88936cc2daf5d166 Mon Sep 17 00:00:00 2001 From: Bert Palm <bert.palm@ufz.de> Date: Mon, 27 Jul 2020 14:40:42 +0200 Subject: [PATCH] fixed logging, added debug message indicates the test that run. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit i removed the setup of the logging module from the core. It interferes with the needs of the user of the lib (saqc). eg. Messages are double printed or not at all. >> It is strongly advised that you do not add any handlers other than >> NullHandler to your library’s loggers. [...] from https://docs.python.org/3/howto/logging.html we might add a defalutLoggingSetup(log_level='INFO') function or similar in future, to ease the setup the logging. --- saqc/__main__.py | 15 +++++++++++++-- saqc/core/core.py | 8 +------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/saqc/__main__.py b/saqc/__main__.py index 061731173..65e7c8686 100644 --- a/saqc/__main__.py +++ b/saqc/__main__.py @@ -5,13 +5,16 @@ import click import numpy as np import pandas as pd +import logging -from saqc.core import SaQC, logger +from saqc.core import SaQC from saqc.flagger import CategoricalFlagger from saqc.flagger.dmpflagger import DmpFlagger import dios +logger = logging.getLogger("SaQC") + FLAGGERS = { "numeric": CategoricalFlagger([-1, 0, 1]), "category": CategoricalFlagger(["NIL", "OK", "BAD"]), @@ -19,6 +22,14 @@ FLAGGERS = { } +def _setup_logging(loglvl): + logger.setLevel(loglvl) + handler = logging.StreamHandler() + formatter = logging.Formatter("[%(asctime)s][%(name)s][%(levelname)s]: %(message)s") + handler.setFormatter(formatter) + logger.addHandler(handler) + + @click.command() @click.option( "-c", "--config", type=click.Path(exists=True), required=True, help="path to the configuration file", @@ -37,7 +48,7 @@ FLAGGERS = { @click.option("--fail/--no-fail", default=True, help="whether to stop the program run on errors") def main(config, data, flagger, outfile, nodata, log_level, fail): - logger.setLevel(log_level) + _setup_logging(log_level) data = pd.read_csv(data, index_col=0, parse_dates=True,) data = dios.DictOfSeries(data) diff --git a/saqc/core/core.py b/saqc/core/core.py index 08dd3927a..8467d07e3 100644 --- a/saqc/core/core.py +++ b/saqc/core/core.py @@ -90,13 +90,6 @@ def _setup(): pd.set_option("mode.chained_assignment", "warn") np.seterr(invalid="ignore") - # logging - logger.setLevel(logging.INFO) - handler = logging.StreamHandler() - formatter = logging.Formatter("[%(asctime)s][%(name)s][%(levelname)s]: %(message)s") - handler.setFormatter(formatter) - logger.addHandler(handler) - _setup() @@ -157,6 +150,7 @@ class SaQC: data, flagger = self._data, self._flagger for field, func in self._to_call: + logger.debug(f"processing: {field}, {func.__name__}, {func.kwargs}") try: data_result, flagger_result = func(data=data, flagger=flagger, field=field) -- GitLab