Skip to content

Commit

Permalink
docs(get_logger): add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Jul 16, 2020
1 parent 476e625 commit e92a612
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions frappe/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@


def get_logger(module, with_more_info=False, _site=None):
"""Application Logger for your given module
Args:
module (str): Name of your logger and consequently your log file.
with_more_info (bool, optional): Will log the form dict using the SiteContextFilter. Defaults to False.
_site (str, optional): If set, validates the current site context with the passed value. The `frappe.web` logger uses this to determine that the application is logging information related to the logger called. Defaults to None.
Returns:
<class 'logging.Logger'>: Returns a Python logger object with Site and Bench level logging capabilities.
"""
global site

def allow_site():
allow = False
if site: allow = True
if _site: allow = site == _site
return allow

if module in frappe.loggers:
return frappe.loggers[module]

Expand All @@ -37,8 +54,8 @@ def get_logger(module, with_more_info=False, _site=None):
formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
handler = RotatingFileHandler(LOG_FILENAME, maxBytes=100_000, backupCount=20)
logger.addHandler(handler)
#
if site == _site:

if allow_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 e92a612

Please sign in to comment.