From 997cfdcb02eb749611d62d8e7b77a1a81ce9d21e Mon Sep 17 00:00:00 2001 From: Gabo Date: Wed, 28 Oct 2020 19:08:01 -0500 Subject: [PATCH] Add notice warn and error log levels --- lib/linter.sh | 9 +++++++++ lib/log.sh | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index f63d4756..5d159412 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -30,6 +30,15 @@ export LOG_DEBUG # Boolean to see verbose logs (info function) LOG_VERBOSE=$(if [[ ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi) export LOG_VERBOSE +# Boolean to see notice logs +LOG_NOTICE=$(if [[ ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi) +export LOG_NOTICE +# Boolean to see warn logs +LOG_WARN=$(if [[ ${LOG_LEVEL} == "WARN" || ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi) +export LOG_WARN +# Boolean to see error logs +LOG_ERROR=$(if [[ ${LOG_LEVEL} == "ERROR" || ${LOG_LEVEL} == "WARN" || ${LOG_LEVEL} == "NOTICE" || ${LOG_LEVEL} == "VERBOSE" || ${LOG_LEVEL} == "DEBUG" || ${LOG_LEVEL} == "TRACE" ]]; then echo "true"; fi) +export LOG_ERROR ######################### # Source Function Files # diff --git a/lib/log.sh b/lib/log.sh index a7ab55d9..cf8be6c9 100644 --- a/lib/log.sh +++ b/lib/log.sh @@ -41,13 +41,13 @@ log() { fi ) } -trace() { log "${LOG_TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE ]${NC} $*${NC}"; } -debug() { log "${LOG_DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG ]${NC} $*${NC}"; } -info() { log "${LOG_VERBOSE:-}" "${NC}$(date +"%F %T") ${F[B]}[INFO ]${NC} $*${NC}"; } -notice() { log "true" "${NC}$(date +"%F %T") ${F[G]}[NOTICE]${NC} $*${NC}"; } -warn() { log "true" "${NC}$(date +"%F %T") ${F[Y]}[WARN ]${NC} $*${NC}"; } -error() { log "true" "${NC}$(date +"%F %T") ${F[R]}[ERROR ]${NC} $*${NC}"; } +trace() { log "${LOG_TRACE:-}" "${NC}$(date +"%F %T") ${F[B]}[TRACE]${NC} $*${NC}"; } +debug() { log "${LOG_DEBUG:-}" "${NC}$(date +"%F %T") ${F[B]}[DEBUG]${NC} $*${NC}"; } +info() { log "${LOG_VERBOSE:-}" "${NC}$(date +"%F %T") ${F[B]}[INFO]${NC} $*${NC}"; } +notice() { log "${LOG_NOTICE:-}" "${NC}$(date +"%F %T") ${F[G]}[NOTICE]${NC} $*${NC}"; } +warn() { log "${LOG_WARN:-}" "${NC}$(date +"%F %T") ${F[Y]}[WARN]${NC} $*${NC}"; } +error() { log "${LOG_ERROR:-}" "${NC}$(date +"%F %T") ${F[R]}[ERROR]${NC} $*${NC}"; } fatal() { - log "true" "${NC}$(date +"%F %T") ${B[R]}${F[W]}[FATAL ]${NC} $*${NC}" + log "true" "${NC}$(date +"%F %T") ${B[R]}${F[W]}[FATAL]${NC} $*${NC}" exit 1 }