diff --git a/docs/releases/2.0.rst b/docs/releases/2.0.rst index 228b7f78e6..33db362a39 100644 --- a/docs/releases/2.0.rst +++ b/docs/releases/2.0.rst @@ -305,6 +305,14 @@ processing. This allows API users to have the document id of the document just uploaded and perform other actions on it while it becomes ready for access. +Auto logging +------------ +App logging to the console is now automatically enabled. If Django's DEBUG +flag is `True` the default level for auto logging is `DEBUG`. If Django's +DEBUG flag is `False` (as in production), the default level changes to `INFO`. +This should make it easier to add relevant messages to issue tickets as +well as a adecuate logging during production. + Other changes ------------- diff --git a/mayan/apps/common/apps.py b/mayan/apps/common/apps.py index 85f76801b7..4b8138ca28 100644 --- a/mayan/apps/common/apps.py +++ b/mayan/apps/common/apps.py @@ -25,6 +25,7 @@ from .links import ( ) from .literals import DELETE_STALE_UPLOADS_INTERVAL from .menus import menu_facet, menu_main, menu_secondary, menu_tools +from .settings import setting_auto_logging from .tasks import task_delete_stale_uploads # NOQA - Force task registration logger = logging.getLogger(__name__) @@ -52,6 +53,18 @@ class MayanAppConfig(apps.AppConfig): ) ), + if setting_auto_logging.value: + if settings.DEBUG: + level = 'DEBUG' + else: + level = 'INFO' + + settings.LOGGING['loggers'][self.name] = { + 'handlers': ['console'], + 'propagate': True, + 'level': level, + } + class CommonApp(MayanAppConfig): app_url = '' diff --git a/mayan/apps/common/settings.py b/mayan/apps/common/settings.py index 404493773f..9e446b0a37 100644 --- a/mayan/apps/common/settings.py +++ b/mayan/apps/common/settings.py @@ -28,3 +28,10 @@ setting_paginate_by = namespace.add_setting( 'An integer specifying how many objects should be displayed per page.' ) ) +setting_auto_logging = namespace.add_setting( + global_name='COMMON_AUTO_LOGGING', + default=True, + help_text=_( + 'Automatically enable logging to all apps.' + ) +) diff --git a/mayan/settings/base.py b/mayan/settings/base.py index d4081ff1ed..5181a7b135 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -212,6 +212,23 @@ COMPRESS_CSS_FILTERS = ( COMPRESS_ENABLED = False COMPRESS_PARSER = 'compressor.parser.HtmlParser' # --------- Django ------------------- +LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'formatters': { + 'intermediate': { + 'format': '%(name)s <%(process)d> [%(levelname)s] "%(funcName)s() %(message)s"' + }, + }, + 'handlers': { + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'intermediate' + } + }, + 'loggers': {} +} LOGIN_URL = 'authentication:login_view' LOGIN_REDIRECT_URL = 'common:home' INTERNAL_IPS = ('127.0.0.1',)