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.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-06-02 21:34:04 -04:00
parent 15badf4ff9
commit e2f95b4d48
3 changed files with 20 additions and 5 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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=_(