diff --git a/allianceauth/project_template/project_name/settings/base.py b/allianceauth/project_template/project_name/settings/base.py index 72c1ddb8..c9a45b6f 100644 --- a/allianceauth/project_template/project_name/settings/base.py +++ b/allianceauth/project_template/project_name/settings/base.py @@ -221,7 +221,7 @@ LOGGING = { 'backupCount': 5, # edit this line to change number of log backups }, 'extension_file': { - 'level': 'DEBUG', + 'level': 'INFO', 'class': 'logging.handlers.RotatingFileHandler', 'filename': os.path.join(BASE_DIR, 'log/extensions.log'), 'formatter': 'verbose', diff --git a/allianceauth/project_template/project_name/settings/local.py b/allianceauth/project_template/project_name/settings/local.py index 786bf38c..8761facb 100644 --- a/allianceauth/project_template/project_name/settings/local.py +++ b/allianceauth/project_template/project_name/settings/local.py @@ -22,6 +22,10 @@ INSTALLED_APPS += [ ] +# To change the logging level for extensions, uncomment the following line. +# LOGGING['handlers']['extension_file']['level'] = 'DEBUG' + + # Enter credentials to use MySQL/MariaDB. Comment out to use sqlite3 DATABASES['default'] = { 'ENGINE': 'django.db.backends.mysql', diff --git a/allianceauth/services/hooks.py b/allianceauth/services/hooks.py index 10a30fa3..455319f3 100644 --- a/allianceauth/services/hooks.py +++ b/allianceauth/services/hooks.py @@ -14,20 +14,22 @@ def get_extension_logger(name): Takes the name of a plugin/extension and generates a child logger of the extensions logger to be used by the extension to log events to the extensions logger. - The logging level is decided by whether or not DEBUG is set to true in the project settings. If - DEBUG is set to false, then the logging level is set to INFO. + The logging level is determined by the level defined for the parent logger. :param: name: the name of the extension doing the logging :return: an extensions child logger """ + if not isinstance(name, str): + raise TypeError(f"get_extension_logger takes an argument of type string." + f"Instead received argument of type {type(name).__name__}.") + import logging - from django.conf import settings + + parent_logger = logging.getLogger('extensions') logger = logging.getLogger('extensions.' + name) logger.name = name - logger.level = logging.INFO - if settings.DEBUG: - logger.level = logging.DEBUG + logger.level = parent_logger.level return logger diff --git a/docs/development/custom/logging.md b/docs/development/custom/logging.md index edba7315..02c253eb 100644 --- a/docs/development/custom/logging.md +++ b/docs/development/custom/logging.md @@ -12,4 +12,22 @@ logger = get_extension_logger(__name__) ``` This works by creating a child logger of the extension logger which propagates all log entries -to the parent (extensions) logger. \ No newline at end of file +to the parent (extensions) logger. + +## Changing the Logging Level +By default, the extension logger's level is set to `DEBUG`. +To change this, uncomment (or add) the following line in `local.py`. + +```python +LOGGING['handlers']['extension_file']['level'] = 'INFO' +``` +*(Remember to restart your supervisor workers after changes to `local.py`)* + +This will change the logger's level to the level you define. + +Options are: *(all options accept entries of levels listed below them)* +* `DEBUG` +* `INFO` +* `WARNING` +* `ERROR` +* `CRITICAL`