From d990062e1a45aaa13b13070daab531011a77d6e2 Mon Sep 17 00:00:00 2001 From: Ken Wills Date: Wed, 4 Sep 2019 14:12:01 -0500 Subject: [PATCH] CLOUD-3370 - Error in configure_logger_category.sh causes logging levels configuration to fail --- .../added/launch/configure_logger_category.sh | 2 +- .../logging/configure-logging-category.bats | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/os-eap7-launch/added/launch/configure_logger_category.sh b/os-eap7-launch/added/launch/configure_logger_category.sh index f209cd68..14c909de 100644 --- a/os-eap7-launch/added/launch/configure_logger_category.sh +++ b/os-eap7-launch/added/launch/configure_logger_category.sh @@ -37,7 +37,7 @@ add_logger_category() { logger=$(echo "$i" | sed 's/ //g') logger_category=$(echo $logger | awk -F':' '{print $1}') logger_level=$(echo $logger | awk -F':' '{print $2}') - if [[ ! "${allowed_log_levels[@]}" =~ " ${logger_level}" ]]; then + if [[ ! "${allowed_log_levels[@]}" =~ "${logger_level}" ]]; then log_warning "Log Level ${logger_level} is not allowed, the allowed levels are ${allowed_log_levels[@]}" else log_info "Configuring logger category ${logger_category} with level ${logger_level:-FINE}" diff --git a/os-eap7-launch/tests/bats/logging/configure-logging-category.bats b/os-eap7-launch/tests/bats/logging/configure-logging-category.bats index b4c2391a..c3d90089 100644 --- a/os-eap7-launch/tests/bats/logging/configure-logging-category.bats +++ b/os-eap7-launch/tests/bats/logging/configure-logging-category.bats @@ -44,6 +44,38 @@ EOF [ "${result}" = "${expected}" ] } +@test "Add ALL logger category" { + #this is the return of xmllint --xpath "//*[local-name()='subsystem']//*[local-name()='logger'][@category='com.my.package']" $CONFIG_FILE + expected=$(cat < +EOF +) + LOGGER_CATEGORIES=com.my.package:ALL + run add_logger_category + result=$(xmllint --xpath "//*[local-name()='subsystem']//*[local-name()='logger'][@category='com.my.package']" $CONFIG_FILE) + result="$(echo "${result}" | sed 's|\\n||g' | xmllint --format --noblanks -)" + expected=$(echo "${expected}" | sed 's|\\n||g' | xmllint --format --noblanks -) + echo "Expected: ${expected}" + echo "Result: ${result}" + [ "${result}" = "${expected}" ] +} + +@test "Add TRACE logger category" { + #this is the return of xmllint --xpath "//*[local-name()='subsystem']//*[local-name()='logger'][@category='com.my.package']" $CONFIG_FILE + expected=$(cat < +EOF +) + LOGGER_CATEGORIES=com.my.package:TRACE + run add_logger_category + result=$(xmllint --xpath "//*[local-name()='subsystem']//*[local-name()='logger'][@category='com.my.package']" $CONFIG_FILE) + result="$(echo "${result}" | sed 's|\\n||g' | xmllint --format --noblanks -)" + expected=$(echo "${expected}" | sed 's|\\n||g' | xmllint --format --noblanks -) + echo "Expected: ${expected}" + echo "Result: ${result}" + [ "${result}" = "${expected}" ] +} + @test "Add 2 logger categories" { #this is the return of xmllint --xpath "//*[local-name()='subsystem']//*[local-name()='logger']" $CONFIG_FILE expected=$(cat < + + +EOF +) + LOGGER_CATEGORIES=" com.my.package:ALL,my.other.package:ERROR,my.another.package" + run add_logger_category + result=$(xmllint --xpath "//*[local-name()='subsystem']//*[local-name()='logger'][@category='com.my.package' or @category='my.other.package' or @category='my.another.package']" $CONFIG_FILE) + result="$(echo "${result}" | sed 's|\\n||g' | xmllint --format --noblanks -)" + expected=$(echo "${expected}" | sed 's|\\n||g' | xmllint --format --noblanks -) + echo "Expected: ${expected}" + echo "Result: ${result}" + [ "${result}" = "${expected}" ] +} + @test "Add 2 logger categories one with invalid log level" { #this is the return of xmllint --xpath "//*[local-name()='subsystem']//*[local-name()='logger']" $CONFIG_FILE expected=$(cat <