|
|
e965a0 |
From 44221b0c9970f11451016f4566602932861458e6 Mon Sep 17 00:00:00 2001
|
|
|
e965a0 |
From: Dalibor Pospisil <dapospis@redhat.com>
|
|
|
e965a0 |
Date: Fri, 2 Feb 2018 15:06:58 +0100
|
|
|
e965a0 |
Subject: [PATCH 4/5] extended coloring capabilities
|
|
|
e965a0 |
|
|
|
e965a0 |
this change allow to color result from other placed
|
|
|
e965a0 |
---
|
|
|
e965a0 |
src/logging.sh | 72 ++++++++++++++++++++++++++++++++++++++--------------------
|
|
|
e965a0 |
1 file changed, 48 insertions(+), 24 deletions(-)
|
|
|
e965a0 |
|
|
|
e965a0 |
diff --git a/src/logging.sh b/src/logging.sh
|
|
|
e965a0 |
index 38a0466..59709df 100644
|
|
|
e965a0 |
--- a/src/logging.sh
|
|
|
e965a0 |
+++ b/src/logging.sh
|
|
|
e965a0 |
@@ -57,41 +57,65 @@ __INTERNAL_PrintText() {
|
|
|
e965a0 |
__INTERNAL_LogText "$@"
|
|
|
e965a0 |
}
|
|
|
e965a0 |
|
|
|
e965a0 |
+# $1 - text to color
|
|
|
e965a0 |
+# $2 - variable to put the color sequence to
|
|
|
e965a0 |
+# $3 - variable to put the uncolor sequence to
|
|
|
e965a0 |
+__INTERNAL_get_prio_colors() {
|
|
|
e965a0 |
+ local prio="$1" var_color="$2" var_uncolor="$3"
|
|
|
e965a0 |
+ local ____COLOR='' ____UNCOLOR=''
|
|
|
e965a0 |
+ if [[ -t 2 ]]; then
|
|
|
e965a0 |
+ ____UNCOLOR="$__INTERNAL_color_reset"
|
|
|
e965a0 |
+ case ${prio^^} in
|
|
|
e965a0 |
+ DEBUG*)
|
|
|
e965a0 |
+ ____COLOR="$__INTERNAL_color_purple"
|
|
|
e965a0 |
+ ;;
|
|
|
e965a0 |
+ PASS)
|
|
|
e965a0 |
+ ____COLOR="$__INTERNAL_color_green"
|
|
|
e965a0 |
+ ;;
|
|
|
e965a0 |
+ FAIL|FATAL)
|
|
|
e965a0 |
+ ____COLOR="$__INTERNAL_color_light_red"
|
|
|
e965a0 |
+ ;;
|
|
|
e965a0 |
+ LOG)
|
|
|
e965a0 |
+ ____COLOR="$__INTERNAL_color_cyan"
|
|
|
e965a0 |
+ ;;
|
|
|
e965a0 |
+ LOG|INFO|BEGIN)
|
|
|
e965a0 |
+ ____COLOR="$__INTERNAL_color_blue"
|
|
|
e965a0 |
+ ;;
|
|
|
e965a0 |
+ WARN*|SKIP*)
|
|
|
e965a0 |
+ ____COLOR="$__INTERNAL_color_yellow"
|
|
|
e965a0 |
+ ;;
|
|
|
e965a0 |
+ esac
|
|
|
e965a0 |
+ fi
|
|
|
e965a0 |
+ eval "$var_color=\"${____COLOR}\""
|
|
|
e965a0 |
+ eval "$var_uncolor=\"${____UNCOLOR}\""
|
|
|
e965a0 |
+}
|
|
|
e965a0 |
+
|
|
|
e965a0 |
+# $1 - text to color
|
|
|
e965a0 |
+# $2 - variable to put the result to
|
|
|
e965a0 |
+__INTERNAL_colorize_prio() {
|
|
|
e965a0 |
+ local prio="$1" var="$2"
|
|
|
e965a0 |
+ local COLOR='' UNCOLOR=''
|
|
|
e965a0 |
+ __INTERNAL_get_prio_colors "$prio" COLOR UNCOLOR
|
|
|
e965a0 |
+ eval "$var=\"$COLOR$prio$UNCOLOR\""
|
|
|
e965a0 |
+}
|
|
|
e965a0 |
+
|
|
|
e965a0 |
+# $1 - MESSAGE
|
|
|
e965a0 |
+# $2 - prio
|
|
|
e965a0 |
+# $3 - LOGFILE
|
|
|
e965a0 |
+# $4 - MESSAGE_COLORED, if empty MESSAGE is used
|
|
|
e965a0 |
__INTERNAL_LogText() {
|
|
|
e965a0 |
local MESSAGE="$1"
|
|
|
e965a0 |
- local MESSAGE_COLORED="${MESSAGE}"
|
|
|
e965a0 |
+ local MESSAGE_COLORED="${4:-"$MESSAGE"}"
|
|
|
e965a0 |
local prio="$2"
|
|
|
e965a0 |
local LOGFILE=${3:-$OUTPUTFILE}
|
|
|
e965a0 |
local res=0
|
|
|
e965a0 |
local COLOR='' UNCOLOR=''
|
|
|
e965a0 |
- if [[ -t 2 ]]; then
|
|
|
e965a0 |
- UNCOLOR="$__INTERNAL_color_reset"
|
|
|
e965a0 |
- case ${prio^^} in
|
|
|
e965a0 |
- DEBUG*)
|
|
|
e965a0 |
- COLOR="$__INTERNAL_color_purple"
|
|
|
e965a0 |
- ;;
|
|
|
e965a0 |
- PASS)
|
|
|
e965a0 |
- COLOR="$__INTERNAL_color_green"
|
|
|
e965a0 |
- ;;
|
|
|
e965a0 |
- FAIL|FATAL)
|
|
|
e965a0 |
- COLOR="$__INTERNAL_color_light_red"
|
|
|
e965a0 |
- ;;
|
|
|
e965a0 |
- LOG)
|
|
|
e965a0 |
- COLOR="$__INTERNAL_color_cyan"
|
|
|
e965a0 |
- ;;
|
|
|
e965a0 |
- LOG|INFO|BEGIN)
|
|
|
e965a0 |
- COLOR="$__INTERNAL_color_blue"
|
|
|
e965a0 |
- ;;
|
|
|
e965a0 |
- WARN*|SKIP*)
|
|
|
e965a0 |
- COLOR="$__INTERNAL_color_yellow"
|
|
|
e965a0 |
- ;;
|
|
|
e965a0 |
- esac
|
|
|
e965a0 |
- fi
|
|
|
e965a0 |
[[ -n "$prio" ]] && {
|
|
|
e965a0 |
local left=$(( (10+${#prio})/2 ))
|
|
|
e965a0 |
local prefix prefix_colored timestamp
|
|
|
e965a0 |
__INTERNAL_SET_TIMESTAMP
|
|
|
e965a0 |
printf -v timestamp "%($__INTERNAL_TIMEFORMAT_SHORT)T" "$__INTERNAL_TIMESTAMP"
|
|
|
e965a0 |
+ __INTERNAL_get_prio_colors "$prio" COLOR UNCOLOR
|
|
|
e965a0 |
printf -v prefix_colored ":: [ %s ] :: [%s%*s%*s%s] ::" "$timestamp" "$COLOR" "$left" "${prio}" "$(( 10-$left ))" '' "$UNCOLOR"
|
|
|
e965a0 |
printf -v prefix ":: [ %s ] :: [%*s%*s] ::" "$timestamp" "$left" "${prio}" "$(( 10-$left ))"
|
|
|
e965a0 |
MESSAGE="$prefix $MESSAGE"
|
|
|
e965a0 |
--
|
|
|
e965a0 |
2.14.3
|