From: John Mulligan Date: Tue, 22 Aug 2023 15:16:48 +0000 (-0400) Subject: cephadm: combine common logging config elements X-Git-Tag: v19.0.0~509^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=27279b91d58a2402218519a6db7e8c501a7804de;p=ceph-ci.git cephadm: combine common logging config elements Move and combine some of the common logging configuration elements. This helps highlight what is the same and what is different between the standard and interactive logging configs. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadmlib/logging.py b/src/cephadm/cephadmlib/logging.py index b682da90384..aa01fbb900e 100644 --- a/src/cephadm/cephadmlib/logging.py +++ b/src/cephadm/cephadmlib/logging.py @@ -11,28 +11,40 @@ from .context import CephadmContext from .constants import QUIET_LOG_LEVEL, LOG_DIR +class _ExcludeErrorsFilter(logging.Filter): + def filter(self, record: logging.LogRecord) -> bool: + """Only lets through log messages with log level below WARNING .""" + return record.levelno < logging.WARNING + + +_common_formatters = { + 'cephadm': { + 'format': '%(asctime)s %(thread)x %(levelname)s %(message)s' + }, +} + + +_log_file_handler = { + 'level': 'DEBUG', + 'class': 'logging.handlers.WatchedFileHandler', + 'formatter': 'cephadm', + 'filename': '%s/cephadm.log' % LOG_DIR, +} + + # During normal cephadm operations (cephadm ls, gather-facts, etc ) we use: # stdout: for JSON output only # stderr: for error, debug, info, etc _logging_config = { 'version': 1, 'disable_existing_loggers': True, - 'formatters': { - 'cephadm': { - 'format': '%(asctime)s %(thread)x %(levelname)s %(message)s' - }, - }, + 'formatters': _common_formatters, 'handlers': { 'console': { 'level': 'INFO', 'class': 'logging.StreamHandler', }, - 'log_file': { - 'level': 'DEBUG', - 'class': 'logging.handlers.WatchedFileHandler', - 'formatter': 'cephadm', - 'filename': '%s/cephadm.log' % LOG_DIR, - } + 'log_file': _log_file_handler, }, 'loggers': { '': { @@ -43,12 +55,6 @@ _logging_config = { } -class _ExcludeErrorsFilter(logging.Filter): - def filter(self, record: logging.LogRecord) -> bool: - """Only lets through log messages with log level below WARNING .""" - return record.levelno < logging.WARNING - - # When cephadm is used as standard binary (bootstrap, rm-cluster, etc) we use: # stdout: for debug and info # stderr: for errors and warnings @@ -60,11 +66,7 @@ _interactive_logging_config = { } }, 'disable_existing_loggers': True, - 'formatters': { - 'cephadm': { - 'format': '%(asctime)s %(thread)x %(levelname)s %(message)s' - }, - }, + 'formatters': _common_formatters, 'handlers': { 'console_stdout': { 'level': 'INFO', @@ -77,12 +79,7 @@ _interactive_logging_config = { 'class': 'logging.StreamHandler', 'stream': sys.stderr }, - 'log_file': { - 'level': 'DEBUG', - 'class': 'logging.handlers.WatchedFileHandler', - 'formatter': 'cephadm', - 'filename': '%s/cephadm.log' % LOG_DIR, - } + 'log_file': _log_file_handler, }, 'loggers': { '': {