blob: 256d0915b74300fd0ee88baf64ac91fe27f399f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/usr/bin/env bash
readonly BASH_LIB_NAME=DEMO
source ./bash-lib.sh
# Set `DEMO_DEBUG=1` to enable debug messages
trace "this is a trace message" "with additional data"
debug "this is a debugging message" "with additional data"
info "this is an informational message" "with additional data"
warn "this is a warning message" "with additional data"
error "this is an error message" "with additional data"
# Like echo, but to stderr
echoe '------------------------------'
if is_debug; then
info "Debugging messages:" on
else
info "Debugging messages:" off
fi
if is_trace; then
info "Trace messages:" on
else
info "Trace messages:" off
fi
echoe '------------------------------'
# Use critical with `set +e` if you want to trap errors
(
function handle_error() {
info "handling error..."
}
set +e
trap "handle_error" ERR
critical "this is a critical error:" "this will allow some error recovery"
info "but with 'set +e', the program continues its course"
)
echoe '------------------------------'
info "use 'fatal()' in either case if you want to quit with an error message"
fatal "some unrecoverable error occurred, exiting"
|