Activate colored output

This commit is contained in:
Gerhard Hoffmann 2023-03-31 09:45:57 +02:00
parent 87be571e43
commit 9dd7eb7a3c

View File

@ -1,6 +1,10 @@
#!/bin/bash #!/bin/bash
# set -x # set -x
RED='\e[0;31m'
GREEN='\e[0;32m'
NC='\e[0m' # No Color
if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
readonly log_helpers_sourced=${BASH_SOURCE[0]} readonly log_helpers_sourced=${BASH_SOURCE[0]}
@ -47,32 +51,32 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
log_info() { log_info() {
if [ $log_level -le $INFO ]; then if [ $log_level -le $INFO ]; then
log "INFO $*" log "${GREEN}INFO $*"
fi fi
} }
log_warn() { log_warn() {
if [ $log_level -le $WARN ]; then if [ $log_level -le $WARN ]; then
log "WARN $*" log "${RED}WARN $*"
fi fi
} }
log_crit() { log_crit() {
if [ $log_level -le $CRIT ]; then if [ $log_level -le $CRIT ]; then
log "CRIT $*" log "${RED}CRIT $*"
fi fi
} }
log_error() { log_error() {
if [ $log_level -le $ERROR ]; then if [ $log_level -le $ERROR ]; then
log "ERROR $*" log "${RED}ERROR $*"
fi fi
} }
log_fatal() { log_fatal() {
if [ $log_level -le $FATAL ]; then if [ $log_level -le $FATAL ]; then
log "FATAL $*" log "${RED}FATAL $*"
log "exiting ..." log "${RED}exiting ..."
exit 1 exit 1
fi fi
} }