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