-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogging_tools.py
More file actions
56 lines (50 loc) · 1.76 KB
/
Copy pathlogging_tools.py
File metadata and controls
56 lines (50 loc) · 1.76 KB
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
50
51
52
53
54
55
# Copyright 2024 - Andrew Kwok Fai LUI,
# Robotics and Autonomous Systems Group, REF, RI
# and the Queensland University of Technology
__author__ = 'Andrew Lui'
__copyright__ = 'Copyright 2024'
__license__ = 'GPL'
__version__ = '1.0'
__email__ = 'ak.lui@qut.edu.au'
__status__ = 'Development'
import logging, time
# -- The custom logger for the task trees package
class CustomFormatter(logging.Formatter):
""" The custom logger class for the package
:meta private:
"""
grey = '\x1b[38;20m'
cyan ='\x1b[36;20m'
yellow = '\x1b[33;20m'
red = '\x1b[31;20m'
bold_red = '\x1b[31;1m'
reset = '\x1b[0m'
# format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)'
format = '[%(levelname)s] [%(created)16f]: %(message)s'
FORMATS = {
logging.DEBUG: cyan + format + reset,
logging.INFO: grey + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset
}
def format(self, record):
time_format = "%H:%M:%S %f"
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt, datefmt=time_format)
return formatter.format(record)
def formatException(self, exc_info):
result = super().formatException(exc_info)
return repr(result)
# Internal function that intializes the logger
def init_logger():
logger = logging.getLogger('main')
logger.setLevel(logging.INFO)
logger.propagate = False
if not logger.handlers:
ch = logging.StreamHandler()
ch.setFormatter(CustomFormatter())
logger.addHandler(ch)
return logger
# The global object to be imported by other modules
logger = init_logger()