Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions: Only log to stderr on WARN or higher #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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