log to stdout/stderr appropriately

master
Kenneth Barbour 2022-02-02 13:49:23 -05:00
parent 71b0138a74
commit e5bb648c80
1 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,9 @@
# Lines starting with '##' are intended for usage documentation
# Does nothing if not using stdout
function usage() {
grep '^##' "$prog" | sed -e 's/^##\s\?//' -e "s/__PROG__/$me/" 1>&2
if [ -t 1 ]; then
grep '^##' "$prog" | sed -e 's/^##\s\?//' -e "s/__PROG__/$me/" 1>&2
fi
}
function nowstr() {
@ -17,8 +20,8 @@ function log() {
function logerr() {
if [ -t 2 ]; then
printf "$(tput setaf 1)[${me}]$(tput sgr0) ${1}\n" ${@:2}
printf "$(tput setaf 1)[${me}] ERROR:$(tput sgr0) ${1}\n" ${@:2} 1>&2
else
printf "$(nowstr) [${me}] ${1}\n" ${@:2}
printf "$(nowstr) [${me}] ERROR: ${1}\n" ${@:2} 1>&2
fi
}