Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCHEMA] Configure only the bst logger instead of the root logger #1996

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading