log: Accept array for default_log_levels

Currently the default_log_levels parameter accepts only hash or string.
This change adds support for an array value, so that users can use
an array of 'logger=LEVEL' strings.

Change-Id: I8c4358128438700430645df132882ec46a8885b9
This commit is contained in:
Takashi Kajinami 2022-04-03 23:13:15 +09:00
parent fe6612cb6c
commit efd1146993
2 changed files with 24 additions and 9 deletions

View File

@ -134,11 +134,10 @@ define oslo::log(
$fatal_deprecations = $::os_service_default,
){
if is_service_default($default_log_levels) {
$default_log_levels_real = $default_log_levels
} else {
validate_legacy(Hash, 'validate_hash', $default_log_levels)
$default_log_levels_real = join(sort(join_keys_to_values($default_log_levels, '=')), ',')
$default_log_levels_real = $default_log_levels ? {
Hash => join(sort(join_keys_to_values($default_log_levels, '=')), ','),
Array => join(sort($default_log_levels), ','),
default => $default_log_levels
}
# NOTE(mwhahaha): oslo.log doesn't like it when debug is not a proper python

View File

@ -51,9 +51,9 @@ describe 'oslo::log' do
:logging_debug_format_suffix => '%(funcName)s %(pathname)s:%(lineno)d',
:logging_exception_prefix => '%(asctime)s.%(msecs)03d %(process)d ERROR %(name)s %(instance)s',
:logging_user_identity_format => '%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s',
:default_log_levels => {
'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', 'sqlalchemy' => 'WARN',
'suds' => 'INFO', 'iso8601' => 'WARN', 'requests.packages.urllib3.connectionpool' => 'WARN' },
:default_log_levels => [
'amqp=WARN', 'amqplib=WARN', 'boto=WARN', 'sqlalchemy=WARN',
'suds=INFO', 'iso8601=WARN', 'requests.packages.urllib3.connectionpool=WARN' ],
:publish_errors => true,
:instance_format => '[instance: %(uuid)s]',
:instance_uuid_format => '[instance: %(uuid)s]',
@ -81,7 +81,7 @@ describe 'oslo::log' do
is_expected.to contain_keystone_config('DEFAULT/logging_exception_prefix').with_value(
'%(asctime)s.%(msecs)03d %(process)d ERROR %(name)s %(instance)s')
is_expected.to contain_keystone_config('DEFAULT/logging_user_identity_format').with_value(
'%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s')
'%(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s')
is_expected.to contain_keystone_config('DEFAULT/default_log_levels').with_value(
'amqp=WARN,amqplib=WARN,boto=WARN,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,sqlalchemy=WARN,suds=INFO')
is_expected.to contain_keystone_config('DEFAULT/publish_errors').with_value(true)
@ -91,6 +91,22 @@ describe 'oslo::log' do
end
end
context 'with default_log_levels set to hash' do
let :params do
{
:default_log_levels => {
'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', 'sqlalchemy' => 'WARN',
'suds' => 'INFO', 'iso8601' => 'WARN', 'requests.packages.urllib3.connectionpool' => 'WARN'
},
}
end
it 'configures logging' do
is_expected.to contain_keystone_config('DEFAULT/default_log_levels').with_value(
'amqp=WARN,amqplib=WARN,boto=WARN,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,sqlalchemy=WARN,suds=INFO')
end
end
context 'with debug as an empty string' do
let :params do
{ :debug => '' }