-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use standard python logging facilities #5
- Loading branch information
Zoia
committed
Jan 28, 2019
1 parent
6932fd1
commit d8da4b9
Showing
4 changed files
with
36 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,18 @@ | ||
import json | ||
import logging | ||
import logging.config | ||
|
||
from JDI.core.logger.log_levels import LogLevels | ||
from JDI.core.settings.jdi_settings import PropertyPath | ||
|
||
|
||
class JDILogger(object): | ||
JDI_LOGGING_CONFIG_FILE_PATH = PropertyPath().get_property_file(file_name_init="logging.json") | ||
|
||
def __init__(self, name="JDI Logger"): | ||
self.logger = logging.getLogger(name) | ||
self.__basic_settings() | ||
|
||
log_level = {LogLevels.INFO, LogLevels.FATAL, LogLevels.ERROR} | ||
|
||
def info(self, log_msg): | ||
if LogLevels.INFO in self.log_level: | ||
self.logger.setLevel(LogLevels.INFO.value[0]) | ||
self.logger.info(log_msg) | ||
|
||
def debug(self, log_msg): | ||
if LogLevels.DEBUG in self.log_level: | ||
self.logger.setLevel(LogLevels.DEBUG.value[0]) | ||
self.logger.debug(log_msg) | ||
|
||
def fatal(self, log_msg): | ||
if LogLevels.FATAL in self.log_level: | ||
self.logger.setLevel(LogLevels.FATAL.value[0]) | ||
self.logger.fatal(log_msg) | ||
|
||
def warning(self, log_msg): | ||
if LogLevels.WARNING in self.log_level: | ||
self.logger.setLevel(LogLevels.WARNING.value[0]) | ||
self.logger.warning(log_msg) | ||
|
||
def error(self, log_msg): | ||
if LogLevels.ERROR in self.log_level: | ||
self.logger.setLevel(LogLevels.ERROR.value[0]) | ||
self.logger.error(log_msg) | ||
|
||
def __basic_settings(self): | ||
hdlr = logging.FileHandler('jdi.log') | ||
hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) | ||
self.logger.addHandler(hdlr) | ||
with open(self.JDI_LOGGING_CONFIG_FILE_PATH, 'r') as fd: | ||
logging.config.dictConfig(json.load(fd)) | ||
self.logger = logging.getLogger(name) | ||
|
||
def __getattr__(self, name): | ||
return getattr(self.logger, name) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"version": 1, | ||
"disable_existing_loggers": true, | ||
"formatters": { | ||
"simple": { | ||
"class": "logging.Formatter", | ||
"datefmt": "%I:%M:%S", | ||
"format": "%(asctime)s %(levelname)s %(message)s" | ||
} | ||
}, | ||
"handlers": { | ||
"file_handler": { | ||
"level": "INFO", | ||
"class": "logging.handlers.WatchedFileHandler", | ||
"formatter": "simple", | ||
"filename": "jdi.log", | ||
"mode": "a", | ||
"encoding": "utf-8" | ||
} | ||
}, | ||
"loggers": { }, | ||
"root": { | ||
"handlers": ["file_handler"], | ||
"level": "DEBUG" | ||
} | ||
} |