Module dcm2bids.utils.logger
Setup logging configuration
View Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 | # -*- coding: utf-8 -*-
"""Setup logging configuration"""
import logging
import sys
def setup_logging(log_level, log_file=None):
""" Setup logging configuration"""
# Check level
level = getattr(logging, log_level.upper(), None)
if not isinstance(level, int):
raise ValueError(f"Invalid log level: {log_level}")
fh = logging.FileHandler(log_file)
# fh.setFormatter(formatter)
fh.setLevel("DEBUG")
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(log_level)
sh_fmt = logging.Formatter(fmt="%(levelname)-8s| %(message)s")
sh.setFormatter(sh_fmt)
# default formatting is kept for the log file"
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s.%(msecs)02d - %(levelname)-8s - %(module)s.%(funcName)s | "
"%(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[fh, sh]
)
|
Functions
setup_logging
| def setup_logging(
log_level,
log_file=None
)
|
Setup logging configuration
View Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 | def setup_logging(log_level, log_file=None):
""" Setup logging configuration"""
# Check level
level = getattr(logging, log_level.upper(), None)
if not isinstance(level, int):
raise ValueError(f"Invalid log level: {log_level}")
fh = logging.FileHandler(log_file)
# fh.setFormatter(formatter)
fh.setLevel("DEBUG")
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(log_level)
sh_fmt = logging.Formatter(fmt="%(levelname)-8s| %(message)s")
sh.setFormatter(sh_fmt)
# default formatting is kept for the log file"
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s.%(msecs)02d - %(levelname)-8s - %(module)s.%(funcName)s | "
"%(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[fh, sh]
)
|
Last update:
2023-08-31
Created:
2023-08-31