From e6a8a40b0bff5d344f030d084746826cf071e003 Mon Sep 17 00:00:00 2001 From: Fede Raimondo Date: Thu, 5 Dec 2024 10:19:59 +0100 Subject: [PATCH] Configure only the bst logger instead of the root logger --- tools/schemacode/src/bidsschematools/render/tables.py | 3 --- tools/schemacode/src/bidsschematools/render/text.py | 3 --- tools/schemacode/src/bidsschematools/schema.py | 4 ---- tools/schemacode/src/bidsschematools/utils.py | 11 ++++++++++- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/schemacode/src/bidsschematools/render/tables.py b/tools/schemacode/src/bidsschematools/render/tables.py index 8eb6b386a4..87af49b04e 100644 --- a/tools/schemacode/src/bidsschematools/render/tables.py +++ b/tools/schemacode/src/bidsschematools/render/tables.py @@ -14,9 +14,6 @@ from bidsschematools.utils import get_logger, set_logger_level lgr = get_logger() -# Basic settings for output, for now just basic -set_logger_level(lgr, os.environ.get("BIDS_SCHEMA_LOG_LEVEL", logging.INFO)) -logging.basicConfig(format="%(asctime)-15s [%(levelname)8s] %(message)s") # Remember to add extension (.html or .md) to the paths when using them. ENTITIES_PATH = "SPEC_ROOT/appendices/entities" diff --git a/tools/schemacode/src/bidsschematools/render/text.py b/tools/schemacode/src/bidsschematools/render/text.py index ce70ae0ded..c2939310de 100644 --- a/tools/schemacode/src/bidsschematools/render/text.py +++ b/tools/schemacode/src/bidsschematools/render/text.py @@ -11,9 +11,6 @@ from bidsschematools.utils import get_logger, set_logger_level lgr = get_logger() -# Basic settings for output, for now just basic -set_logger_level(lgr, os.environ.get("BIDS_SCHEMA_LOG_LEVEL", logging.INFO)) -logging.basicConfig(format="%(asctime)-15s [%(levelname)8s] %(message)s") # Remember to add extension (.html or .md) to the paths when using them. ENTITIES_PATH = "SPEC_ROOT/appendices/entities" diff --git a/tools/schemacode/src/bidsschematools/schema.py b/tools/schemacode/src/bidsschematools/schema.py index a00eaddac9..0cefc725aa 100644 --- a/tools/schemacode/src/bidsschematools/schema.py +++ b/tools/schemacode/src/bidsschematools/schema.py @@ -21,10 +21,6 @@ from .types import Namespace lgr = utils.get_logger() -# Basic settings for output, for now just basic -utils.set_logger_level(lgr, os.environ.get("BIDS_SCHEMA_LOG_LEVEL", logging.INFO)) -logging.basicConfig(format="%(asctime)-15s [%(levelname)8s] %(message)s") - class BIDSSchemaError(Exception): """Errors indicating invalid values in the schema itself""" diff --git a/tools/schemacode/src/bidsschematools/utils.py b/tools/schemacode/src/bidsschematools/utils.py index 6f9850edb0..c518a88bb5 100644 --- a/tools/schemacode/src/bidsschematools/utils.py +++ b/tools/schemacode/src/bidsschematools/utils.py @@ -1,6 +1,7 @@ """Utility functions for the bids-specification schema.""" import logging +import os from . import data @@ -29,7 +30,15 @@ def get_logger(name=None): logging.Logger logger object. """ - return logging.getLogger("bidsschematools" + (".%s" % name if name else "")) + logger = logging.getLogger("bidsschematools" + (".%s" % name if name else "")) + # Basic settings for output, for now just basic + set_logger_level(logger, os.environ.get("BIDS_SCHEMA_LOG_LEVEL", logging.INFO)) + format="%(asctime)-15s [%(levelname)8s] %(message)s" + for lh in logger.handlers: + lh.setFormatter(logging.Formatter(format)) + + return logger + def set_logger_level(lgr, level):