diff options
author | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2014-05-16 19:48:18 -0400 |
---|---|---|
committer | Davanum Srinivas <dims@linux.vnet.ibm.com> | 2014-07-05 16:50:04 -0400 |
commit | 5fd77ebc726c1263bdd393beaab4782e5e763d4d (patch) | |
tree | eecf09f06b04fce35c1c2545cda6889e4250abf2 | |
parent | b8db732f226f97bd6028b21420f7f7577e1a2720 (diff) | |
download | oslo-incubator-5fd77ebc726c1263bdd393beaab4782e5e763d4d.tar.gz |
Ability to customize default_log_levels for each project
Add a new parameter default_log_levels to log.set_defaults. We
need to default its value to None since this is a backwards
incompatible change otherwise. However, if someone is not setting
a specific value, we do need to set the usual default levels
exposed DEFAULT_LOG_LEVELS public variable so others can use
the default log levels to construct their custom defaults.
Change-Id: I49a82c5b3446784d254ca558f51b6c3e5c2028eb
Closes-Bug: #1297950
-rw-r--r-- | openstack/common/log.py | 32 | ||||
-rw-r--r-- | tests/unit/test_log.py | 12 |
2 files changed, 30 insertions, 14 deletions
diff --git a/openstack/common/log.py b/openstack/common/log.py index 9c0d1937..ad065ee4 100644 --- a/openstack/common/log.py +++ b/openstack/common/log.py @@ -120,6 +120,12 @@ generic_log_opts = [ help='Log output to standard error.') ] +DEFAULT_LOG_LEVELS = ['amqp=WARN', 'amqplib=WARN', 'boto=WARN', + 'qpid=WARN', 'sqlalchemy=WARN', 'suds=INFO', + 'oslo.messaging=INFO', 'iso8601=WARN', + 'requests.packages.urllib3.connectionpool=WARN', + 'urllib3.connectionpool=WARN'] + log_opts = [ cfg.StrOpt('logging_context_format_string', default='%(asctime)s.%(msecs)03d %(process)d %(levelname)s ' @@ -138,18 +144,7 @@ log_opts = [ '%(instance)s', help='Prefix each line of exception output with this format.'), cfg.ListOpt('default_log_levels', - default=[ - 'amqp=WARN', - 'amqplib=WARN', - 'boto=WARN', - 'qpid=WARN', - 'sqlalchemy=WARN', - 'suds=INFO', - 'oslo.messaging=INFO', - 'iso8601=WARN', - 'requests.packages.urllib3.connectionpool=WARN', - 'urllib3.connectionpool=WARN' - ], + default=DEFAULT_LOG_LEVELS, help='List of logger=LEVEL pairs.'), cfg.BoolOpt('publish_errors', default=False, @@ -410,9 +405,18 @@ def setup(product_name, version='unknown'): sys.excepthook = _create_logging_excepthook(product_name) -def set_defaults(logging_context_format_string): +def set_defaults(logging_context_format_string, + default_log_levels=None): + # Just in case the caller is not setting the + # default_log_level. This is insurance because + # we introduced the default_log_level parameter + # later in a backwards in-compatible change + if default_log_levels is None: + default_log_levels = DEFAULT_LOG_LEVELS cfg.set_defaults( - log_opts, logging_context_format_string=logging_context_format_string) + log_opts, + logging_context_format_string=logging_context_format_string, + default_log_levels=default_log_levels) def _find_facility_from_conf(): diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py index 5651aa58..7f045828 100644 --- a/tests/unit/test_log.py +++ b/tests/unit/test_log.py @@ -538,6 +538,12 @@ class SetDefaultsTestCase(test_base.BaseTestCase): self.conf([]) self.assertIsNone(self.conf.logging_context_format_string) + def test_default_log_level_to_none(self): + log.set_defaults(logging_context_format_string=None, + default_log_levels=None) + self.conf([]) + self.assertEqual(log.DEFAULT_LOG_LEVELS, self.conf.default_log_levels) + def test_change_default(self): my_default = '%(asctime)s %(levelname)s %(name)s [%(request_id)s '\ '%(user_id)s %(project)s] %(instance)s'\ @@ -546,6 +552,12 @@ class SetDefaultsTestCase(test_base.BaseTestCase): self.conf([]) self.assertEqual(self.conf.logging_context_format_string, my_default) + def test_change_default_log_level(self): + log.set_defaults(logging_context_format_string=None, + default_log_levels=['foo=bar']) + self.conf([]) + self.assertEqual(['foo=bar'], self.conf.default_log_levels) + class LogConfigOptsTestCase(test_base.BaseTestCase): |