summaryrefslogtreecommitdiff
path: root/lib/log.source.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/log.source.sh')
-rw-r--r--lib/log.source.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/log.source.sh b/lib/log.source.sh
new file mode 100644
index 0000000..56c6587
--- /dev/null
+++ b/lib/log.source.sh
@@ -0,0 +1,30 @@
+# Log a message.
+log () {
+ local -r level="$1"; shift
+ local message
+
+ for message in "$@"; do
+ echo "$message"
+ done | log::_pipe "$level"
+}
+
+# Log a stream through a pipe.
+log::pipe () {
+ log::_pipe "$1"
+}
+
+# Internal log implementation.
+log::_pipe () {
+ local -r level="$1"; shift
+
+ if [[ "$level" == VERBOSE && -z "$LOG_VERBOSE" ]]; then
+ return
+ fi
+
+ local -r callee=${FUNCNAME[2]}
+ local -r stamp=$($DATE +%Y%m%d-%H%M%S)
+
+ while read -r line; do
+ echo "$level|$stamp|$callee|$line" >&2
+ done
+}