diff options
| author | Paul Buetow <git@mx.buetow.org> | 2021-05-25 22:10:09 +0100 |
|---|---|---|
| committer | Paul Buetow <git@mx.buetow.org> | 2021-05-25 22:10:09 +0100 |
| commit | 2a3fa5b8c749e631d2d7ed1bb01300f023c4b9ea (patch) | |
| tree | 46761b18297bc50e70fb61bef6031b33d5e31db5 /lib/log.source.sh | |
| parent | b7489882bc82e4266e9cb9845604acdf20857c23 (diff) | |
rename packages to lib1.0.0
Diffstat (limited to 'lib/log.source.sh')
| -rw-r--r-- | lib/log.source.sh | 30 |
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 +} |
