diff --git a/Okiru b/Okiru index 415226d..f1ddc40 100755 --- a/Okiru +++ b/Okiru @@ -31,6 +31,9 @@ WHITE='\033[0;37m' GRAY='\033[1;37m' 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 #+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" fi } -#Debugging level logging; can be toggled via a switch -debug () { - printf "${BLUE}[DEBUG]: $1${STOP}\n" - if [[ -f $LOG ]]; then - echo -e "$(date | awk '{print $4}') [DEBUG]: $1" >> $LOG - fi -} +#If VERBOSE mode is enabled, print debug messages +if [[ -n $VERBOSE ]]; then + #Debugging level logging; can be toggled via a switch + debug () { + printf "${BLUE}[DEBUG]: $1${STOP}\n" + if [[ -f $LOG ]]; then + echo -e "$(date +"%T:%N") [DEBUG]: $1" >> $LOG + fi + } +#Otherwise, ignore debug calls; +else + debug () { + : + } +fi #Information level logging; info () { - printf "${CYAN}[INFO]:${STOP} $1\n" - if [[ -f $LOG ]]; then - echo -e "$(date | awk '{print $4}') [INFO]: $1" >> $LOG + if [[ -z $2 ]]; then + printf "${CYAN}[INFO]:${STOP} %s\n" "$1" + 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 } #Warning level logging; warn () { printf "${YELLOW}[WARNING]:${STOP} $1\n" if [[ -f $LOG ]]; then - echo -e "$(date | awk '{print $4}') [WARN]: $1" >> $LOG + echo -e "$(date +"%T:%N") [WARN]: $1" >> $LOG fi } #Error logging function; Errors are added to an array and a report file. error () { - echo $1 1>&2 -# ` ^ Output error message to stderr printf "${RED}[ERROR]: $1${STOP}\n" # ^ Print it to the screen errors+=("$1") # ^ And add to errors array 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 fi if [[ -f $REPORT ]]; then @@ -118,7 +134,7 @@ error () { ok () { printf "${GREEN}[SUCCESS]: $1${STOP}\n" if [[ -f $LOG ]]; then - echo -e "$(date | awk '{print $4}') [SUCCESS]: $1" >> $LOG + echo -e "$(date +"%T:%N") [SUCCESS]: $1" >> $LOG fi }