-
Notifications
You must be signed in to change notification settings - Fork 21
/
logger.py
26 lines (19 loc) · 748 Bytes
/
logger.py
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
import logging
import sys
LOGGER = logging.getLogger()
FORMATTER = logging.Formatter("%(asctime)s - %(levelname)s - %(funcName)s - %(message)s")
def setup_logger(out_file=None, stdout=True, stdout_level=logging.INFO, file_level=logging.DEBUG):
LOGGER.handlers = []
LOGGER.setLevel(min(stdout_level, file_level))
if stdout:
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(FORMATTER)
handler.setLevel(stdout_level)
LOGGER.addHandler(handler)
if out_file is not None:
handler = logging.FileHandler(out_file)
handler.setFormatter(FORMATTER)
handler.setLevel(file_level)
LOGGER.addHandler(handler)
LOGGER.info("logger set up")
return LOGGER