forked from CameronDeweerd/FFXIV-Market-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_handler.py
61 lines (53 loc) · 1.89 KB
/
log_handler.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Module for handling the supply of loggers for FFXIV-Market-Calculator
"""
import logging
class LogHandler: # pylint: disable=too-few-public-methods
"""
Class for handling the script discord api calls.
Attributes:
-------
_LOG : Logger object
Holds the logger object
Methods:
-------
__create_logger(module, logging_config):
Creates a new logger
get_logger(module, logging_config):
Retrieves a logger for the calling module
"""
_LOG = None
@staticmethod
def __create_logger(module, logging_config):
"""
A private method that interacts with the python
logging module
"""
# Initialize the class variable with logger object
LogHandler._LOG = logging.getLogger(module)
if logging_config['log_mode'] == "APPEND":
log_mode = 'a'
else:
log_mode = 'w'
logging.basicConfig(level=logging.INFO,
format='%(asctime)s\t%(levelname)s\t\t%(name)s\t\t%(message)s',
datefmt="%Y-%m-%d %H:%M:%S",
filename=logging_config['log_file'],
filemode=log_mode)
# set the logging level based on the user selection
if logging_config['log_level'] == "INFO":
LogHandler._LOG.setLevel(logging.INFO)
elif logging_config['log_level'] == "ERROR":
LogHandler._LOG.setLevel(logging.ERROR)
elif logging_config['log_level'] == "DEBUG":
LogHandler._LOG.setLevel(logging.DEBUG)
return LogHandler._LOG
@staticmethod
def get_logger(module, logging_config):
"""
A static method called by other modules to initialize logger in
their own module
"""
logger = LogHandler.__create_logger(module, logging_config)
# return the logger object
return logger