[hopem,r=gnuoy]

Set root logger level to DEBUG in /etc/logging.conf
if debug is True otherwise keystone logger remains
as WARNING.

Closes-Bug: 1407317
This commit is contained in:
Edward Hope-Morley 2015-01-19 10:45:41 +00:00
parent 040aa5dee3
commit 928a2ef915
4 changed files with 69 additions and 0 deletions

View File

@ -134,3 +134,14 @@ class KeystoneContext(context.OSContextGenerator):
resolve_address(ADMIN),
api_port('keystone-admin')).rstrip('v2.0')
return ctxt
class KeystoneLoggingContext(context.OSContextGenerator):
def __call__(self):
ctxt = {}
debug = config('debug')
if debug and debug.lower() in ['yes', 'true']:
ctxt['root_level'] = 'DEBUG'
return ctxt

View File

@ -100,6 +100,7 @@ API_PORTS = {
}
KEYSTONE_CONF = "/etc/keystone/keystone.conf"
KEYSTONE_LOGGER_CONF = "/etc/keystone/logging.conf"
KEYSTONE_CONF_DIR = os.path.dirname(KEYSTONE_CONF)
STORED_PASSWD = "/var/lib/keystone/keystone.passwd"
STORED_TOKEN = "/var/lib/keystone/keystone.token"
@ -125,6 +126,10 @@ BASE_RESOURCE_MAP = OrderedDict([
context.BindHostContext(),
context.WorkerConfigContext()],
}),
(KEYSTONE_LOGGER_CONF, {
'contexts': [keystone_context.KeystoneLoggingContext()],
'services': BASE_SERVICES,
}),
(HAPROXY_CONF, {
'contexts': [context.HAProxyContext(singlenode_mode=True),
keystone_context.HAProxyContext()],

View File

@ -0,0 +1,43 @@
[loggers]
keys=root
[formatters]
keys=normal,normal_with_name,debug
[handlers]
keys=production,file,devel
[logger_root]
{% if root_level -%}
level={{ root_level }}
{% else -%}
level=WARNING
{% endif -%}
handlers=file
[handler_production]
class=handlers.SysLogHandler
level=ERROR
formatter=normal_with_name
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
[handler_file]
class=FileHandler
level=DEBUG
formatter=normal_with_name
args=('/var/log/keystone/keystone.log', 'a')
[handler_devel]
class=StreamHandler
level=NOTSET
formatter=debug
args=(sys.stdout,)
[formatter_normal]
format=%(asctime)s %(levelname)s %(message)s
[formatter_normal_with_name]
format=(%(name)s): %(asctime)s %(levelname)s %(message)s
[formatter_debug]
format=(%(name)s): %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s

View File

@ -119,3 +119,13 @@ class TestKeystoneContexts(CharmTestCase):
msg = "Multiple networks configured but net_type" \
" is None (os-public-network)."
mock_log.assert_called_with(msg, level="WARNING")
@patch.object(context, 'config')
def test_keystone_logger_context(self, mock_config):
ctxt = context.KeystoneLoggingContext()
mock_config.return_value = None
self.assertEqual({}, ctxt())
mock_config.return_value = 'True'
self.assertEqual({'root_level': 'DEBUG'}, ctxt())