From 060c0967dbd539fe2a218c22a5b385294e13959f Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Wed, 1 May 2013 14:29:23 -0400 Subject: Deprecate log_format and change default to None Commit 3e71cc4c8c7e08784f44c2e337a585e562b93ec5 fixed an issue with ignoring log_format, but changed the default logging formatter. This led to being unable to use the former context aware formatter without configuring log_format='' explicitly. This change sets log_format to None so that the default is a context aware formatter, but setting log_format works as intended. Additionally, since log_format is mutually exclusive with some of the other config formatting options, such as logging_default_format_string, it should be deprecated. Bug 1167388 Change-Id: I281ed7fe3448403f27a4cd318fc21915027906cc --- openstack/common/log.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'openstack') diff --git a/openstack/common/log.py b/openstack/common/log.py index 1599dbf..d7ba467 100644 --- a/openstack/common/log.py +++ b/openstack/common/log.py @@ -48,7 +48,6 @@ from openstack.common import local from openstack.common import notifier -_DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" _DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" common_cli_opts = [ @@ -73,11 +72,13 @@ logging_cli_opts = [ 'documentation for details on logging configuration ' 'files.'), cfg.StrOpt('log-format', - default=_DEFAULT_LOG_FORMAT, + default=None, metavar='FORMAT', help='A logging.Formatter log message format string which may ' 'use any of the available logging.LogRecord attributes. ' - 'Default: %(default)s'), + 'This option is deprecated. Please use ' + 'logging_context_format_string and ' + 'logging_default_format_string instead.'), cfg.StrOpt('log-date-format', default=_DEFAULT_LOG_DATE_FORMAT, metavar='DATE_FORMAT', @@ -429,13 +430,17 @@ def _setup_logging_from_conf(): if CONF.publish_errors: log_root.addHandler(PublishErrorsHandler(logging.ERROR)) + datefmt = CONF.log_date_format for handler in log_root.handlers: - datefmt = CONF.log_date_format + # NOTE(alaski): CONF.log_format overrides everything currently. This + # should be deprecated in favor of context aware formatting. if CONF.log_format: handler.setFormatter(logging.Formatter(fmt=CONF.log_format, datefmt=datefmt)) + log_root.info('Deprecated: log_format is now deprecated and will ' + 'be removed in the next release') else: - handler.setFormatter(LegacyFormatter(datefmt=datefmt)) + handler.setFormatter(ContextFormatter(datefmt=datefmt)) if CONF.debug: log_root.setLevel(logging.DEBUG) @@ -481,7 +486,7 @@ class WritableLogger(object): self.logger.log(self.level, msg) -class LegacyFormatter(logging.Formatter): +class ContextFormatter(logging.Formatter): """A context.RequestContext aware formatter configured through flags. The flags used to set format strings are: logging_context_format_string -- cgit