diff --git a/tools/schemacode/src/bidsschematools/render/tables.py b/tools/schemacode/src/bidsschematools/render/tables.py index 8eb6b386a4..4b91b223e5 100644 --- a/tools/schemacode/src/bidsschematools/render/tables.py +++ b/tools/schemacode/src/bidsschematools/render/tables.py @@ -2,8 +2,6 @@ from __future__ import annotations -import logging -import os import typing as ty import pandas as pd @@ -11,12 +9,9 @@ from bidsschematools.render import utils from bidsschematools.schema import BIDSSchemaError, Namespace, filter_schema -from bidsschematools.utils import get_logger, set_logger_level +from bidsschematools.utils import get_logger 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..226b1d408b 100644 --- a/tools/schemacode/src/bidsschematools/render/text.py +++ b/tools/schemacode/src/bidsschematools/render/text.py @@ -1,19 +1,13 @@ """Functions for rendering portions of the schema as text.""" -import logging -import os - import yaml from markdown_it import MarkdownIt from bidsschematools.render import utils from bidsschematools.schema import Namespace, filter_schema, load_schema -from bidsschematools.utils import get_logger, set_logger_level +from bidsschematools.utils import get_logger 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..ad6462f32c 100644 --- a/tools/schemacode/src/bidsschematools/schema.py +++ b/tools/schemacode/src/bidsschematools/schema.py @@ -1,7 +1,6 @@ """Schema loading- and processing-related functions.""" import json -import logging import os import re import sys @@ -21,9 +20,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): diff --git a/tools/schemacode/src/bidsschematools/utils.py b/tools/schemacode/src/bidsschematools/utils.py index 6f9850edb0..441e8986eb 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,19 @@ 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" + if len(logger.handlers) == 0: + # add a handler if there isn't one + ch = logging.StreamHandler() + logger.addHandler(ch) + # Set the formatter for the handlers + for lh in logger.handlers: + lh.setFormatter(logging.Formatter(format)) + + return logger def set_logger_level(lgr, level):