improve performance & debug

This commit is contained in:
Florian Bezannier
2021-04-30 10:26:55 +02:00
parent 86cb20f9e6
commit 5f75d3fb30
16 changed files with 117 additions and 121 deletions
+12 -4
View File
@@ -5,18 +5,26 @@ DEBUG_LEVELV_NUM = 9
logging.addLevelName(DEBUG_LEVELV_NUM, "DEBUGV")
def debugv(self, message, *args, **kws):
self.log(DEBUG_LEVELV_NUM, message, *args, **kws)
class CustomLogger(logging.Logger):
# pylint: disable=too-many-arguments
def __new_style_log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, **kwargs):
if kwargs.pop('style', "%") == "{": # optional
msg = msg.format(*args)
args = []
super()._log(level, msg, args, exc_info, extra, stack_info)
def debugv(self, msg, *args, **kwargs):
if self.isEnabledFor(DEBUG_LEVELV_NUM):
self.__new_style_log(DEBUG_LEVELV_NUM, msg, args, **kwargs)
logging.Logger.debugv = debugv
logging.setLoggerClass(CustomLogger)
# pylint: disable=invalid-name
logger = logging.getLogger("log")
def my_logger(file='activity.log', handler_level=logging.INFO):
global logger
logger.setLevel(handler_level)
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
file_handler = RotatingFileHandler(file, 'a', 1000000, 1, encoding='utf8')