diff --git a/example/verbose.sh b/example/verbose.sh new file mode 100644 index 0000000..10d2e9b --- /dev/null +++ b/example/verbose.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +source "$(cd "${BASH_SOURCE[0]%/*}" && pwd)/../lib/oo-bootstrap.sh" + +import util/log + +namespace test/verbose +VERBOSE=2 + +Log::AddOutput test/verbose DEBUG + +Log "this log will be printed" +V=2 Log "this log will be displayed" + +VERBOSE=1 +V=2 Log "this log will not be displayed" diff --git a/lib/util/log.sh b/lib/util/log.sh index b67e9a6..77aff72 100644 --- a/lib/util/log.sh +++ b/lib/util/log.sh @@ -36,6 +36,12 @@ Log::DisableFilter() { } Log() { + # support verbosing logging + local V="${V:-0}" + if [[ $VERBOSE < $V ]]; then + return + fi + local callingFunction="${FUNCNAME[1]}" local callingScript="${BASH_SOURCE[1]}" local scope