-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.py
33 lines (28 loc) · 1.34 KB
/
Utils.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
import sys
import logging
def configure_logging(verbosity):
# Setting the format of the logs
FORMAT = "[%(asctime)s] %(levelname)s: %(message)s"
# Configuring the logging system to the lowest level
logging.basicConfig(level=logging.DEBUG, format=FORMAT, stream=sys.stderr)
# Defining the ANSI Escape characters
BOLD = '\033[1m'
DEBUG = '\033[92m'
INFO = '\033[94m'
WARNING = '\033[93m'
ERROR = '\033[91m'
END = '\033[0m'
# Coloring the log levels
if sys.stderr.isatty():
logging.addLevelName(logging.ERROR, "%s%s%s%s%s" % (BOLD, ERROR, "GAP_DAEMON_ERROR", END, END))
logging.addLevelName(logging.WARNING, "%s%s%s%s%s" % (BOLD, WARNING, "GAP_DAEMON_WARNING", END, END))
logging.addLevelName(logging.INFO, "%s%s%s%s%s" % (BOLD, INFO, "GAP_DAEMON_INFO", END, END))
logging.addLevelName(logging.DEBUG, "%s%s%s%s%s" % (BOLD, DEBUG, "GAP_DAEMON_DEBUG", END, END))
else:
logging.addLevelName(logging.ERROR, "GAP_DAEMON_ERROR")
logging.addLevelName(logging.WARNING, "GAP_DAEMON_WARNING")
logging.addLevelName(logging.INFO, "GAP_DAEMON_INFO")
logging.addLevelName(logging.DEBUG, "GAP_DAEMON_DEBUG")
# Setting the level of the logs
level = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][verbosity]
logging.getLogger().setLevel(level)