Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Commit

Permalink
Добавил имя класса ошибки к msg (#11)
Browse files Browse the repository at this point in the history
* Добавил имя класса ошибки к msg

* Добавил имя класса ошибки к msg
  • Loading branch information
gomonuk authored and arturgspb committed Oct 31, 2018
1 parent fd3975c commit 77b25cc
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions metaappscriptsdk/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

from metaappscriptsdk.logger import LOGGER_ENTITY

def preprocessing(func):
def wrapper(self, msg, context=None):
""" Этот декоратор занимается предобработкой входных параметров:
1. Проверяет context на None.
2. Добавляет к msg имя класса объекта ошибки. Например: msg + ModuleNotFoundError
"""
if context is None:
context = {}

error_obj = context.get('e')
if isinstance(error_obj, Exception):
try:
msg = msg + ' ' + str(error_obj.__class__.__name__)
except:
pass


return func(self, msg, context)
return wrapper

class Logger:
"""
Expand All @@ -22,22 +41,18 @@ def info(self, msg, context=None):
context = {}
logging.info(msg, extra={'context': context})

def warning(self, msg, context=None):
if context is None:
context = {}
@preprocessing
def warning(self, msg, context):
logging.warning(msg, extra={'context': context})

def error(self, msg, context=None):
if context is None:
context = {}
@preprocessing
def error(self, msg, context):
logging.error(msg, extra={'context': context})

def critical(self, msg, context=None):
if context is None:
context = {}
@preprocessing
def critical(self, msg, context):
logging.critical(msg, extra={'context': context})

def exception(self, msg, context=None):
if context is None:
context = {}
@preprocessing
def exception(self, msg, context):
logging.exception(msg, extra={'context': context})

0 comments on commit 77b25cc

Please sign in to comment.