diff options
| author | Paul Bütow <snonux@users.noreply.github.com> | 2021-05-21 05:12:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-21 05:12:35 +0100 |
| commit | b2d00167fa2df42808e2c95cba47d28279ce81cd (patch) | |
| tree | 35b44d3a2795f8064e12562d69d226d128f79561 /packages/log.source.sh | |
| parent | 7868506c413b453c8c1935f953a0e35a0b4c4ef9 (diff) | |
| parent | 9dbd7f008192fd506bf642944232334fad0ed55c (diff) | |
Merge pull request #1 from snonux/master
Master
Diffstat (limited to 'packages/log.source.sh')
| -rw-r--r-- | packages/log.source.sh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/log.source.sh b/packages/log.source.sh new file mode 100644 index 0000000..56c6587 --- /dev/null +++ b/packages/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 +} |
