update `_filter_service_log` to not use `-i -E`

Moreover, I added a function to print the whole mail log. Appropriate
comments were added to this function to indicate that one should only
use this function when necessary.
This commit is contained in:
georglauterbach 2024-01-20 12:11:26 +01:00
parent 143ca0c27d
commit aaeea8af81
No known key found for this signature in database
GPG Key ID: F367F7C43C118578
2 changed files with 16 additions and 14 deletions

View File

@ -20,22 +20,24 @@ function _should_output_number_of_lines() {
#
# @param ${1} = service name
# @param ${2} = string to filter by
# @param ${3} = container name [OPTIONAL]
#
# ## Attention
#
# The string given to this function is interpreted by `grep -E`, i.e.
# as a regular expression. In case you use characters that are special
# in regular expressions, you need to escape them!
# @param ... = options given to `grep` (which is used to filter logs)
function _filter_service_log() {
local SERVICE=${1:?Service name must be provided}
local STRING=${2:?String to match must be provided}
local CONTAINER_NAME=$(__handle_container_name "${3:-}")
local FILE="/var/log/supervisor/${SERVICE}.log"
shift 2
# Fallback to alternative log location:
[[ -f ${FILE} ]] || FILE="/var/log/mail/${SERVICE}.log"
_run_in_container grep -i -E "${STRING}" "${FILE}"
local FILE="/var/log/supervisor/${SERVICE}.log"
[[ -f ${FILE} ]] || FILE="/var/log/mail/${SERVICE}.log" # Fallback to alternative log location:
_run_in_container grep "${@}" "${STRING}" "${FILE}"
}
# Use this function to print the complete mail log, but use it only where necessary.
# In most cases, you will rather want to filter the log with
#
# 1. _filter_service_log
# 2. _service_log_should_[not_]contain_string
function _show_complete_mail_log() {
_run_in_container cat /var/log/mail/mail.log
}
# Like `_filter_service_log` but asserts that the string was found.

View File

@ -276,7 +276,7 @@ function teardown_file() { _default_teardown ; }
_service_log_should_contain_string 'mail' 'imapsieve: Matched static mailbox rule \[1\]'
_service_log_should_not_contain_string 'mail' 'imapsieve: Matched static mailbox rule \[2\]'
_filter_service_log 'mail' '.'
_show_complete_mail_log
for LINE in "${LEARN_SPAM_LINES[@]}"; do
assert_output --partial "${LINE}"
done
@ -289,7 +289,7 @@ function teardown_file() { _default_teardown ; }
_service_log_should_contain_string 'mail' 'imapsieve: Matched static mailbox rule \[2\]'
_filter_service_log 'mail' '.'
_show_complete_mail_log
for LINE in "${LEARN_HAM_LINES[@]}"; do
assert_output --partial "${LINE}"
done