diff options
| author | Paul Buetow <paul@buetow.org> | 2021-05-12 10:07:06 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-05-12 10:07:06 +0100 |
| commit | c10c16ba69ff74440f03192242741ee2a77d6448 (patch) | |
| tree | bc8037b680222cd40a146aa827e3a3fd489a999e /modules/log.source.sh | |
| parent | 0e4caa074d62c673a26e7b118a9afc6fb1c92ebb (diff) | |
better logging and better testing
Diffstat (limited to 'modules/log.source.sh')
| -rw-r--r-- | modules/log.source.sh | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/log.source.sh b/modules/log.source.sh new file mode 100644 index 00000000..55d693ec --- /dev/null +++ b/modules/log.source.sh @@ -0,0 +1,26 @@ +log () { + local -r level="$1"; shift + + for message in "$@"; do + echo "$message" + done | log::_pipe "$level" +} + +log::pipe () { + log::_pipe "$1" +} + +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 +} |
