Skip to content

Commit

Permalink
functions: Only log to stderr on WARN or higher
Browse files Browse the repository at this point in the history
Closes jirutka#7

Signed-off-by: fossdd <[email protected]>
  • Loading branch information
fossdd committed Aug 15, 2024
1 parent 1704b28 commit dda9cc4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@
# $1: message (defaults is to read from STDIN)
emsg() {
if [ $# -eq 0 ]; then
awk "{ print \"$PROGNAME\", \$0; fflush(); }" >&2
awk "{ print \"$PROGNAME\", \$0; fflush(); }"
else
printf '%s: %s\n' "$PROGNAME" "$1" >&2
printf '%s: %s\n' "$PROGNAME" "$1"
fi
}

# Logs the message from STDIN or $1 with level DEBUG.
# $1: message (defaults is to read from STDIN)
edebug() {
if [ "$DEBUG" ]; then
emsg "debug: $@"
emsg "debug: $@" >&2
elif [ $# -eq 0 ]; then
cat >/dev/null
fi
}

# Logs the message from STDIN or $1 with level INFO.
# $1: message (defaults is to read from STDIN)
einfo() {
emsg "$@"
}

# Logs the message from STDIN on $1 with level WARN.
# $1: message (defaults is to read from STDIN)
ewarn() {
emsg "$@"
emsg "$@" >&2
}

# Logs the error message and exits.
Expand Down

0 comments on commit dda9cc4

Please sign in to comment.