From 7a79870236d0138f812793bb6aa7cfd85d25b381 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Tue, 15 Oct 2024 18:27:28 +0100 Subject: [PATCH] chore(logging): set up logger for package correctly 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. --- neuroml/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/neuroml/__init__.py b/neuroml/__init__.py index b4e140b..3df5a38 100644 --- a/neuroml/__init__.py +++ b/neuroml/__init__.py @@ -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):