Skip to content

Commit

Permalink
chore(logging): set up logger for package correctly
Browse files Browse the repository at this point in the history
So that only loggers for this package use the format string etc.

Otherwise, if we set basicConfig, the module that is imported first gets
its formatter set as the default (pyNeuroML) for example.
  • Loading branch information
sanjayankur31 committed Oct 15, 2024
1 parent e58beaf commit 7a79870
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions neuroml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
from .__version__ import current_neuroml_version as current_neuroml_version
from .nml.nml import * # allows importation of all neuroml classes

logging.basicConfig(
format="libNeuroML >>> %(levelname)s - %(message)s",
level=logging.WARN,
)

# Define a logger for the package
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.propagate = False

ch = logging.StreamHandler()
# do not set level for handler

formatter = logging.Formatter(
"libNeuroML >>> %(asctime)s - %(levelname)s - %(message)s", datefmt="%H:%M:%S"
)
ch.setFormatter(formatter)

logger.addHandler(ch)


def print_(text, verbose=True):
Expand Down

0 comments on commit 7a79870

Please sign in to comment.