Skip to content

Commit 73b0b0d

Browse files
author
Jim Zhang
committed
feat(log): support verbosing logging
1 parent 903fd74 commit 73b0b0d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Diff for: example/verbose.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
source "$(cd "${BASH_SOURCE[0]%/*}" && pwd)/../lib/oo-bootstrap.sh"
3+
4+
import util/log
5+
6+
namespace test/verbose
7+
VERBOSE=2
8+
9+
Log::AddOutput test/verbose DEBUG
10+
11+
Log "this log will be printed"
12+
V=2 Log "this log will be displayed"
13+
14+
VERBOSE=1
15+
V=2 Log "this log will not be displayed"

Diff for: lib/util/log.sh

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Log::DisableFilter() {
3636
}
3737

3838
Log() {
39+
# support verbosing logging
40+
local V="${V:-0}"
41+
if [[ $VERBOSE < $V ]]; then
42+
return
43+
fi
44+
3945
local callingFunction="${FUNCNAME[1]}"
4046
local callingScript="${BASH_SOURCE[1]}"
4147
local scope

0 commit comments

Comments
 (0)