mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-24 07:16:43 +00:00
92fa6c196a
Rename the logging primitive functions and utility functions, prefixing all with 'serval_log', eg: logMessage() -> serval_logf() etc. Add an XPRINTF xhexdump() function and use it to implement the serval_log_hexdump() utility, renamed from dump(). Add macros WHY_dump(), WARN_dump(), HINT_dump() and DEBUG_dump(), and use them everywhere. Remove the 'log.console.dump_config' and 'log.file.dump_config' configuration options; configuration is now dumped in every log prolog. The logging system now constructs the log prolog by invoking the new 'log_prolog' trigger, so that it no longer depends on the version string and configuration system. Any system that wants to present a message in the log prolog can define its own trigger, which calls standard log primitives to print the message. Split the logging system into a front-end (log.c) that provides the logging primitives and is independent of the configuration system, and a set of back-end "outputters" (log_output_console.c, log_output_file.c, log_output_android.c) that may depend on the configuration system and are decoupled from the front-end using the 'logoutput' link section. These log outputters are explicitly linked into executables by the Makefile rules, but could also be linked in using USE_FEATURE(). The USE_FEATURE() calls have _not_ been added to servald_features.c, so that different daemon executables can be built with the same feature set but different log outputs.
207 lines
7.8 KiB
Bash
Executable File
207 lines
7.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tests for Serval DNA logging.
|
|
#
|
|
# Copyright 2013 Serval Project, Inc.
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
setup() {
|
|
setup_servald
|
|
}
|
|
|
|
doc_LogStderrDefault="By default, only errors and warnings are logged to stderr"
|
|
test_LogStderrDefault() {
|
|
execute $servald log error 'hoopla'
|
|
assertExitStatus '==' 0
|
|
assertStderrGrep --matches=1 '^ERROR:.*hoopla$'
|
|
executeOk_servald log warn 'buckle'
|
|
assertStderrGrep --matches=1 '^WARN:.*buckle$'
|
|
executeOk_servald log info 'lymph'
|
|
assertStderrGrep --matches=0 'lymph'
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrGrep --matches=0 'eccles'
|
|
}
|
|
|
|
doc_LogStderrConfigAll="Configure all messages logged to stderr"
|
|
test_LogStderrConfigAll() {
|
|
executeOk_servald config set log.console.level debug
|
|
execute $servald log error 'hoopla'
|
|
assertExitStatus '==' 0
|
|
assertStderrGrep --matches=1 '^ERROR:.*hoopla$'
|
|
executeOk_servald log warn 'buckle'
|
|
assertStderrGrep --matches=1 '^WARN:.*buckle$'
|
|
executeOk_servald log info 'lymph'
|
|
assertStderrGrep --matches=1 'INFO:.*lymph$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrGrep --matches=1 'DEBUG:.*eccles$'
|
|
}
|
|
|
|
doc_LogStderrConfigNone="Configure no messages logged to stderr"
|
|
test_LogStderrConfigNone() {
|
|
executeOk_servald config set log.console.level none
|
|
executeOk_servald log error 'hoopla'
|
|
assertStderrIs ''
|
|
executeOk_servald log warn 'buckle'
|
|
assertStderrIs ''
|
|
executeOk_servald log info 'lymph'
|
|
assertStderrIs ''
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrIs ''
|
|
}
|
|
|
|
doc_LogFileDefault="By Default, all messages are appended to a configured file"
|
|
test_LogFileDefault() {
|
|
executeOk_servald config set log.console.level none
|
|
executeOk_servald config set log.file.path "$PWD/log.txt"
|
|
executeOk_servald log error 'hoopla'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
executeOk_servald log warn 'buckle'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
executeOk_servald log info 'lymph'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt 'DEBUG:.*eccles$'
|
|
}
|
|
|
|
doc_LogFileConfigLevel="Configure level of messages appended to a configured file"
|
|
test_LogFileConfigLevel() {
|
|
executeOk_servald config set log.console.level none
|
|
executeOk_servald config set log.file.level info
|
|
executeOk_servald config set log.file.path "$PWD/log.txt"
|
|
executeOk_servald log warn 'buckle'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=0 log.txt 'DEBUG:.*eccles$'
|
|
executeOk_servald log error 'hoopla'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=0 log.txt 'DEBUG:.*eccles$'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
executeOk_servald log info 'lymph'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=0 log.txt 'DEBUG:.*eccles$'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
}
|
|
|
|
doc_LogFileStderrFile="Log messages to stderr and a configured file"
|
|
test_LogFileStderrFile() {
|
|
executeOk_servald config set log.file.path "$PWD/log.txt"
|
|
executeOk_servald log info 'lymph'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertStderrIs ''
|
|
executeOk_servald log warn 'buckle'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertStderrGrep --matches=1 '^WARN:.*buckle$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrIs ''
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'DEBUG:.*eccles$'
|
|
execute $servald log error 'hoopla'
|
|
assertExitStatus '==' 0
|
|
assertStderrGrep --matches=1 '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'DEBUG:.*eccles$'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
}
|
|
|
|
doc_LogFileRotation="Log file rotation and deletion"
|
|
setup_LogFileRotation() {
|
|
setup
|
|
executeOk_servald config set log.console.level debug \
|
|
set log.console.show_pid true \
|
|
set log.file.level warn
|
|
}
|
|
test_LogFileRotation() {
|
|
executeOk_servald config \
|
|
set log.file.directory_path "$PWD" \
|
|
set log.file.rotate 3 \
|
|
set log.file.duration 2s
|
|
assert --stderr --message="no log files yet" [ $(ls *.log 2>/dev/null | wc -l) -eq 0 ]
|
|
executeOk_servald log warn one
|
|
assert --stderr --message="one log file" [ $(ls *.log | wc -l) -eq 1 ]
|
|
log1=$(ls *.log | tail -n 1)
|
|
sleep 2.1
|
|
executeOk_servald log warn two
|
|
assert --stderr --message="two log files" [ $(ls *.log | wc -l) -eq 2 ]
|
|
log2=$(ls *.log | tail -n 1)
|
|
assert --stderr --message="ascending log file name" [ "$log2" != "$log1" ]
|
|
sleep 2.1
|
|
executeOk_servald log warn three
|
|
assert --stderr --message="three log files" [ $(ls *.log | wc -l) -eq 3 ]
|
|
log3=$(ls *.log | tail -n 1)
|
|
assert --stderr --message="ascending log file name" [ "$log3" != "$log1" -a "$log3" != "$log2" ]
|
|
sleep 2.1
|
|
executeOk_servald log warn four
|
|
assert --stderr --message="three log files" [ $(ls *.log | wc -l) -eq 3 ]
|
|
assert --stderr --message="first log file gone" ! [ -e $log1 ]
|
|
log4=$(ls *.log | tail -n 1)
|
|
assert --stderr --message="ascending log file name" [ "$log4" != "$log2" -a "$log4" != "$log3" -a "$log4" != "$log1" ]
|
|
}
|
|
|
|
doc_LogFileDirectoryAbsolute="Absolute log file directory path"
|
|
test_LogFileDirectoryAbsolute() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.directory_path "$PWD/wakawaka"
|
|
executeOk_servald echo one
|
|
assert --message="exactly one log file" [ $(ls -d wakawaka/*.log | wc -l) -eq 1 ]
|
|
assertGrep wakawaka/*.log '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
doc_LogFileDirectoryRelative="Relative log file directory path"
|
|
test_LogFileDirectoryRelative() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.directory_path "../blah"
|
|
executeOk_servald echo one
|
|
assert --message="exactly one log file" [ $(ls -d "$SERVALINSTANCE_PATH/blah/"*.log | wc -l) -eq 1 ]
|
|
assertGrep "$SERVALINSTANCE_PATH/blah/"*.log '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
doc_LogFileAbsolute="Absolute log file path"
|
|
test_LogFileAbsolute() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.path "$PWD/log.txt"
|
|
executeOk_servald echo one
|
|
assertGrep log.txt '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
doc_LogFileRelative="Relative log file path"
|
|
test_LogFileRelative() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.directory_path "$PWD" \
|
|
set log.file.path "log.txt"
|
|
executeOk_servald echo one
|
|
assertGrep log.txt '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
runTests "$@"
|