diff --git a/HISTORY.rst b/HISTORY.rst index 08c8b7408d..a8aa7466eb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -166,6 +166,8 @@ - All installation artifact are now created and read from the media folder. - Debian is now the Linux distribution used for the Docker image. - Most Docker Celery workers are now execute using a lower OS priority number. +- Add COMMON_PRODUCTION_ERROR_LOGGING setting to control the logging of errors in production. Defaults to False. +- Change the error log file handle class to RotatingFileHandle to avoid an indefinitely growing log file. 2.7.3 (2017-09-11) diff --git a/mayan/apps/common/apps.py b/mayan/apps/common/apps.py index 66d6888d68..53df51ce0d 100644 --- a/mayan/apps/common/apps.py +++ b/mayan/apps/common/apps.py @@ -35,7 +35,10 @@ from .menus import ( ) from .licenses import * # NOQA from .queues import * # NOQA - Force queues registration -from .settings import setting_auto_logging, setting_production_error_log_path +from .settings import ( + setting_auto_logging, setting_production_error_log_path, + setting_production_error_logging +) from .signals import pre_initial_setup, pre_upgrade from .tasks import task_delete_stale_uploads # NOQA - Force task registration from .utils import check_for_sqlite @@ -176,7 +179,7 @@ class CommonApp(MayanAppConfig): level = 'ERROR' handlers = ['console'] - if os.path.exists(settings.MEDIA_ROOT): + if os.path.exists(settings.MEDIA_ROOT) and setting_production_error_logging.value: handlers.append('logfile') loggers = {} @@ -208,11 +211,13 @@ class CommonApp(MayanAppConfig): 'loggers': loggers } - if os.path.exists(settings.MEDIA_ROOT): + if os.path.exists(settings.MEDIA_ROOT) and setting_production_error_logging.value: logging_configuration['handlers']['logfile'] = { - 'class': 'logging.handlers.WatchedFileHandler', + 'backupCount': 3, + 'class': 'logging.handlers.RotatingFileHandler', 'filename': setting_production_error_log_path.value, - 'formatter': 'logfile' + 'formatter': 'logfile', + 'maxBytes': 1024, } logging.config.dictConfig(logging_configuration) diff --git a/mayan/apps/common/settings.py b/mayan/apps/common/settings.py index 4d33f32234..aa78de6fc0 100644 --- a/mayan/apps/common/settings.py +++ b/mayan/apps/common/settings.py @@ -55,6 +55,14 @@ setting_temporary_directory = namespace.add_setting( ), is_path=True ) +setting_production_error_logging = namespace.add_setting( + global_name='COMMON_PRODUCTION_ERROR_LOGGING', + default=False, + help_text=_( + 'Enable error logging outside of the system error logging ' + 'capabilities.' + ) +) setting_production_error_log_path = namespace.add_setting( global_name='COMMON_PRODUCTION_ERROR_LOG_PATH', default=os.path.join(settings.MEDIA_ROOT, 'error.log'), help_text=_(