Skip to content

Commit

Permalink
FIX: Overwrite existing logger handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Sep 26, 2022
1 parent a392c85 commit 90b4c45
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions sdcflows/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Basic miscellaneous utilities."""
import logging


def front(inlist):
Expand Down Expand Up @@ -69,15 +70,15 @@ def get_free_mem():
return None


def create_logger(name: str, level: int = 40):
import logging
def create_logger(name: str, level: int = 40) -> logging.Logger:
logger = logging.getLogger(name)
logger.setLevel(level)

if not logger.handlers:
handler = logging.StreamHandler()
handler.setLevel(level)
formatter = logging.Formatter('[%(name)s %(asctime)s] - %(levelname)s: %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
# clear any existing handlers
logger.handlers.clear()
handler = logging.StreamHandler()
handler.setLevel(level)
# formatter = logging.Formatter('[%(name)s %(asctime)s] - %(levelname)s: %(message)s')
formatter = logging.Formatter('[%(name)s - %(levelname)s]: %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger

0 comments on commit 90b4c45

Please sign in to comment.