Skip to content

Commit

Permalink
[SCHEMA] Configure only the bst logger instead of the root logger (#1996
Browse files Browse the repository at this point in the history
)

* Configure only the bst logger instead of the root logger

* Add a logging handler if there are none

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix flake8
  • Loading branch information
fraimondo authored and effigies committed Dec 5, 2024
1 parent e859546 commit 7309536
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
7 changes: 1 addition & 6 deletions tools/schemacode/src/bidsschematools/render/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

from __future__ import annotations

import logging
import os
import typing as ty

import pandas as pd
from tabulate import tabulate

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"
Expand Down
8 changes: 1 addition & 7 deletions tools/schemacode/src/bidsschematools/render/text.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 0 additions & 4 deletions tools/schemacode/src/bidsschematools/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Schema loading- and processing-related functions."""

import json
import logging
import os
import re
import sys
Expand All @@ -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):
Expand Down
15 changes: 14 additions & 1 deletion tools/schemacode/src/bidsschematools/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utility functions for the bids-specification schema."""

import logging
import os

from . import data

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 7309536

Please sign in to comment.