Commit 33144870 authored by Alessandro Elias's avatar Alessandro Elias

Add helper to log to stdout, stderror and file accordinly.

parent 72193765
[ -n "$QUIET" ] && return 0
readonly ERROR=1
readonly WARNING=2
readonly INFO=4
readonly DEBUG=8
set_quiet () {
if [ "x$QUIET" != "x1" ]; then
exec 6>&1 > "$LOG_FILE"
exec 7>&2 2> "$LOG_FILE"
QUIET=1
VERBOSE_FLAGS=$ERROR
perror () {
if [ $(($VERBOSE_FLAGS & $ERROR)) -eq $ERROR ]; then
echo -e "\033[38;5;9m[error]\033[0m $@" 1>&2
echo -e "\033[38;5;9m[error]\033[0m $@" >> "$LOG_FILE" 1>&2
fi
}
unset_quiet () {
if [ "x$QUIET" == "x1" ]; then
exec 1>&6 6>&-
exec 2>&7 7>&-
exec 6>&2
QUIET=0
pwarning () {
if [ $(($VERBOSE_FLAGS & $WARNING)) -eq $WARNING ]; then
echo -e "\033[38;5;11m[warning]\033[0m $@"
echo -e "\033[38;5;11m[warning]\033[0m $@" >> "$LOG_FILE"
fi
}
pinfo () {
echo -e "\033[38;5;10m[info]\033[0m $TOOL_STR $@" >&6
}
perror () {
echo -e "\033[38;5;9m[error]\033[0m $TOOL_STR $@" >&6
qnd_exit
}
pwarning () {
echo -e "\033[38;5;11m[warning]\033[0m $TOOL_STR $@" >&6
if [ $(($VERBOSE_FLAGS & $INFO)) -eq $WARNING ]; then
echo -e "\033[38;5;10m[info]\033[0m $@"
echo -e "\033[38;5;10m[info]\033[0m $@" >> "$LOG_FILE" 1>&2
fi
}
pdebug () {
if [ "x$QUIET" = "x1" ]; then
echo -e "[DEBUG] $TOOL_STR $@" >&2
else
echo -e "\033[38;5;6m[debug]\033[0m $TOOL_STR $@" >&6
pdebug () {
if [ $(($VERBOSE_FLAGS & $DEBUG)) -eq $DEBUG ]; then
echo -e "\033[38;5;6m[debug]\033[0m $@"
echo -e "\033[38;5;6m[debug]\033[0m $@" >> "$LOG_FILE" 1>&2
fi
}
exec 6>&2
QUIET=0
true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment