Skip to content

Commit

Permalink
Add exception handler in central file
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvrajjain2003 committed Nov 26, 2023
1 parent 5d13c11 commit 0f0c7d2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions clpipe/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
import os
import sys
import logging
from pathlib import Path

Expand Down Expand Up @@ -83,12 +84,21 @@ def resolve_fmriprep_dir(fmriprep_dir):

return fmriprep_root

def exception_handler(exception_type, exception, traceback):
print("%s: %s" % (exception_type.__name__, exception))


def get_logger(name, debug=False, log_dir=None, f_name="clpipe.log"):
logger = logging.getLogger("clpipe").getChild(name)

if debug:
logger.setLevel(logging.DEBUG)
if not debug:
sys.excepthook = exception_handler
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.DEBUG)

# if debug:
# logger.setLevel(logging.DEBUG)

if log_dir:
add_file_handler(log_dir, f_name, logger=logger)
Expand Down

0 comments on commit 0f0c7d2

Please sign in to comment.