Skip to content

Commit

Permalink
fix: Add site validation for logger
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Jul 16, 2020
1 parent e054509 commit 476e625
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions frappe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,10 +1559,10 @@ def _get_doctype_app():

loggers = {}
log_level = None
def logger(module=None, with_more_info=False):
def logger(module=None, with_more_info=False, _site=None):
'''Returns a python logger that uses StreamHandler'''
from frappe.utils.logger import get_logger
return get_logger(module=module, with_more_info=with_more_info)
return get_logger(module=module, with_more_info=with_more_info, _site=_site)

def log_error(message=None, title=_("Error")):
'''Log error to Error Log'''
Expand Down
5 changes: 3 additions & 2 deletions frappe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def application(request):
frappe.monitor.stop(response)
frappe.recorder.dump()

frappe.logger("frappe.web").info({
"site": get_site_name(request.host),
_site = get_site_name(request.host)
frappe.logger("frappe.web", _site=_site).info({
"site": _site,
"remote_addr": getattr(request, "remote_addr", "NOTFOUND"),
"base_url": getattr(request, "base_url", "NOTFOUND"),
"full_path": getattr(request, "full_path", "NOTFOUND"),
Expand Down
4 changes: 2 additions & 2 deletions frappe/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
site = getattr(frappe.local, 'site', None)


def get_logger(module, with_more_info=False):
def get_logger(module, with_more_info=False, _site=None):
global site
if module in frappe.loggers:
return frappe.loggers[module]
Expand All @@ -38,7 +38,7 @@ def get_logger(module, with_more_info=False):
handler = RotatingFileHandler(LOG_FILENAME, maxBytes=100_000, backupCount=20)
logger.addHandler(handler)
#
if site:
if site == _site:
SITELOG_FILENAME = os.path.join(site, 'logs', logfile)
site_handler = RotatingFileHandler(SITELOG_FILENAME, maxBytes=100_000, backupCount=20)
site_handler.setFormatter(formatter)
Expand Down

0 comments on commit 476e625

Please sign in to comment.