|
| 1 | +import json |
1 | 2 | import logging
|
| 3 | +import logging.config |
2 | 4 |
|
3 |
| -from JDI.core.logger.log_levels import LogLevels |
| 5 | +from JDI.core.settings.jdi_settings import PropertyPath |
4 | 6 |
|
5 | 7 |
|
6 | 8 | class JDILogger(object):
|
| 9 | + JDI_LOGGING_CONFIG_FILE_PATH = PropertyPath().get_property_file(file_name_init="logging.json") |
7 | 10 |
|
8 | 11 | def __init__(self, name="JDI Logger"):
|
9 |
| - self.logger = logging.getLogger(name) |
10 |
| - self.__basic_settings() |
11 |
| - |
12 |
| - log_level = {LogLevels.INFO, LogLevels.FATAL, LogLevels.ERROR} |
13 |
| - |
14 |
| - def info(self, log_msg): |
15 |
| - if LogLevels.INFO in self.log_level: |
16 |
| - self.logger.setLevel(LogLevels.INFO.value[0]) |
17 |
| - self.logger.info(log_msg) |
18 |
| - |
19 |
| - def debug(self, log_msg): |
20 |
| - if LogLevels.DEBUG in self.log_level: |
21 |
| - self.logger.setLevel(LogLevels.DEBUG.value[0]) |
22 |
| - self.logger.debug(log_msg) |
23 | 12 |
|
24 |
| - def fatal(self, log_msg): |
25 |
| - if LogLevels.FATAL in self.log_level: |
26 |
| - self.logger.setLevel(LogLevels.FATAL.value[0]) |
27 |
| - self.logger.fatal(log_msg) |
28 |
| - |
29 |
| - def warning(self, log_msg): |
30 |
| - if LogLevels.WARNING in self.log_level: |
31 |
| - self.logger.setLevel(LogLevels.WARNING.value[0]) |
32 |
| - self.logger.warning(log_msg) |
33 |
| - |
34 |
| - def error(self, log_msg): |
35 |
| - if LogLevels.ERROR in self.log_level: |
36 |
| - self.logger.setLevel(LogLevels.ERROR.value[0]) |
37 |
| - self.logger.error(log_msg) |
38 |
| - |
39 |
| - def __basic_settings(self): |
40 |
| - hdlr = logging.FileHandler('jdi.log') |
41 |
| - hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) |
42 |
| - self.logger.addHandler(hdlr) |
| 13 | + with open(self.JDI_LOGGING_CONFIG_FILE_PATH, 'r') as fd: |
| 14 | + logging.config.dictConfig(json.load(fd)) |
| 15 | + self.logger = logging.getLogger(name) |
43 | 16 |
|
| 17 | + def __getattr__(self, name): |
| 18 | + return getattr(self.logger, name) |
0 commit comments