-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
38 lines (28 loc) · 965 Bytes
/
log.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
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Set up the logging environment
Copied from Stack Overflow:
http://stackoverflow.com/questions/7621897/python-logging-module-globally"""
# Imports
import logging
__author__ = "Michael Lane"
__email__ = "[email protected]"
__copyright__ = "Copyright 2017, Michael Lane"
__license__ = "MIT"
def setup_custom_logger(name:str, level:int) -> logging.Logger:
formatter = logging.Formatter(fmt='%(asctime)s - %(levelname)s - %(module)s - %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(name=name)
if level >= 4:
logger.setLevel(logging.DEBUG)
elif level == 3:
logger.setLevel(logging.INFO)
elif level == 2:
logger.setLevel(logging.WARNING)
elif level == 1:
logger.setLevel(logging.ERROR)
else:
logger.setLevel(logging.CRITICAL)
logger.addHandler(handler)
return logger