Split debug to optional verbose mode (inital); do not yell twice to STDERR
This commit is contained in:
46
Okiru
46
Okiru
@@ -31,6 +31,9 @@ WHITE='\033[0;37m'
|
|||||||
GRAY='\033[1;37m'
|
GRAY='\033[1;37m'
|
||||||
STOP="\e[0m"
|
STOP="\e[0m"
|
||||||
|
|
||||||
|
#If passed from calling script, run in verbose mode (enables debug logging level)
|
||||||
|
VERBOSE="$1"
|
||||||
|
|
||||||
|
|
||||||
#If a function calls 'logging' for a log, it will create a log file; otherwise, keep the
|
#If a function calls 'logging' for a log, it will create a log file; otherwise, keep the
|
||||||
#+variable empty thus printing only to terminal
|
#+variable empty thus printing only to terminal
|
||||||
@@ -76,37 +79,50 @@ logging () {
|
|||||||
printf "Logging is ${RED}disabled${STOP}; No log file will be generated.\n"
|
printf "Logging is ${RED}disabled${STOP}; No log file will be generated.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#Debugging level logging; can be toggled via a switch
|
#If VERBOSE mode is enabled, print debug messages
|
||||||
debug () {
|
if [[ -n $VERBOSE ]]; then
|
||||||
printf "${BLUE}[DEBUG]: $1${STOP}\n"
|
#Debugging level logging; can be toggled via a switch
|
||||||
if [[ -f $LOG ]]; then
|
debug () {
|
||||||
echo -e "$(date | awk '{print $4}') [DEBUG]: $1" >> $LOG
|
printf "${BLUE}[DEBUG]: $1${STOP}\n"
|
||||||
fi
|
if [[ -f $LOG ]]; then
|
||||||
}
|
echo -e "$(date +"%T:%N") [DEBUG]: $1" >> $LOG
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
#Otherwise, ignore debug calls;
|
||||||
|
else
|
||||||
|
debug () {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
fi
|
||||||
#Information level logging;
|
#Information level logging;
|
||||||
info () {
|
info () {
|
||||||
printf "${CYAN}[INFO]:${STOP} $1\n"
|
if [[ -z $2 ]]; then
|
||||||
if [[ -f $LOG ]]; then
|
printf "${CYAN}[INFO]:${STOP} %s\n" "$1"
|
||||||
echo -e "$(date | awk '{print $4}') [INFO]: $1" >> $LOG
|
if [[ -f $LOG ]]; then
|
||||||
|
echo -e "$(date +"%T:%N") [INFO]: $1" >> $LOG
|
||||||
|
fi
|
||||||
|
elif [[ -n $2 ]]; then
|
||||||
|
printf "${CYAN}[INFO]:${STOP} %s ${PURPLE}%s${STOP}\n" "$1" "$2"
|
||||||
|
if [[ -f $LOG ]]; then
|
||||||
|
printf "$(date +"%T:%N")${CYAN}[INFO]:${STOP} %s ${PURPLE}%s${STOP}\n" "$1" "$2" >> $LOG
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#Warning level logging;
|
#Warning level logging;
|
||||||
warn () {
|
warn () {
|
||||||
printf "${YELLOW}[WARNING]:${STOP} $1\n"
|
printf "${YELLOW}[WARNING]:${STOP} $1\n"
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [WARN]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [WARN]: $1" >> $LOG
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#Error logging function; Errors are added to an array and a report file.
|
#Error logging function; Errors are added to an array and a report file.
|
||||||
error () {
|
error () {
|
||||||
echo $1 1>&2
|
|
||||||
# ` ^ Output error message to stderr
|
|
||||||
printf "${RED}[ERROR]: $1${STOP}\n"
|
printf "${RED}[ERROR]: $1${STOP}\n"
|
||||||
# ^ Print it to the screen
|
# ^ Print it to the screen
|
||||||
errors+=("$1")
|
errors+=("$1")
|
||||||
# ^ And add to errors array
|
# ^ And add to errors array
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [ERROR]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [ERROR]: $1" >> $LOG
|
||||||
# ^ Log it with its' time and date
|
# ^ Log it with its' time and date
|
||||||
fi
|
fi
|
||||||
if [[ -f $REPORT ]]; then
|
if [[ -f $REPORT ]]; then
|
||||||
@@ -118,7 +134,7 @@ error () {
|
|||||||
ok () {
|
ok () {
|
||||||
printf "${GREEN}[SUCCESS]: $1${STOP}\n"
|
printf "${GREEN}[SUCCESS]: $1${STOP}\n"
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [SUCCESS]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [SUCCESS]: $1" >> $LOG
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user