Skip to content

Commit

Permalink
style: black + restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Jul 30, 2020
1 parent 7bf69c6 commit 090b81f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions frappe/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_logger(module, with_more_info=False, allow_site=True, filter=None):
"""

if allow_site == True:
site = getattr(frappe.local, 'site', None)
site = getattr(frappe.local, "site", None)
elif allow_site:
site = allow_site
else:
Expand All @@ -48,21 +48,21 @@ def get_logger(module, with_more_info=False, allow_site=True, filter=None):
module = "frappe"
with_more_info = True

logfile = module + '.log'
logfile = module + ".log"


LOG_FILENAME = os.path.join('..', 'logs', logfile)
LOG_FILENAME = os.path.join("..", "logs", logfile)

logger = logging.getLogger(LOGGER_NAME)
logger.setLevel(frappe.log_level or default_log_level)
logger.propagate = False

formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
formatter = logging.Formatter("%(asctime)s %(levelname)s %(name)s %(message)s")
handler = RotatingFileHandler(LOG_FILENAME, maxBytes=100_000, backupCount=20)
handler.setFormatter(formatter)
logger.addHandler(handler)

if site:
SITELOG_FILENAME = os.path.join(site, 'logs', logfile)
SITELOG_FILENAME = os.path.join(site, "logs", logfile)
site_handler = RotatingFileHandler(SITELOG_FILENAME, maxBytes=100_000, backupCount=20)
site_handler.setFormatter(formatter)
logger.addHandler(site_handler)
Expand All @@ -73,20 +73,23 @@ def get_logger(module, with_more_info=False, allow_site=True, filter=None):
if filter:
logger.addFilter(filter)

handler.setFormatter(formatter)

frappe.loggers[LOGGER_NAME] = logger

return logger


class SiteContextFilter(logging.Filter):
"""This is a filter which injects request information (if available) into the log."""

def filter(self, record):
if "Form Dict" not in text_type(record.msg):
record.msg = text_type(record.msg) + "\nSite: {0}\nForm Dict: {1}".format(getattr(frappe.local, 'site', None), getattr(frappe.local, 'form_dict', None))
site = getattr(frappe.local, "site", None)
form_dict = getattr(frappe.local, "form_dict", None)
record.msg = text_type(record.msg) + "\nSite: {0}\nForm Dict: {1}".format(site, form_dict)
return True


def set_log_level(level):
'''Use this method to set log level to something other than the default DEBUG'''
frappe.log_level = getattr(logging, (level or '').upper(), None) or default_log_level
"""Use this method to set log level to something other than the default DEBUG"""
frappe.log_level = getattr(logging, (level or "").upper(), None) or default_log_level
frappe.loggers = {}

0 comments on commit 090b81f

Please sign in to comment.