From e952c9d31e6d0bbdc4dd779375804644abbdd924 Mon Sep 17 00:00:00 2001 From: huangjc7 <43225006+huangjc7@users.noreply.github.com> Date: Fri, 28 Feb 2025 00:10:02 +0800 Subject: [PATCH] Add BITNAMI_COLOR to liblog.sh (#76245) * Added BITNAMI_COLOR method, which can control the color switch Signed-off-by: huangjc7 --- .../prebuildfs/opt/bitnami/scripts/liblog.sh | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/bitnami/redis-cluster/7.4/debian-12/prebuildfs/opt/bitnami/scripts/liblog.sh b/bitnami/redis-cluster/7.4/debian-12/prebuildfs/opt/bitnami/scripts/liblog.sh index 450f05bd823f..c233355d98e8 100644 --- a/bitnami/redis-cluster/7.4/debian-12/prebuildfs/opt/bitnami/scripts/liblog.sh +++ b/bitnami/redis-cluster/7.4/debian-12/prebuildfs/opt/bitnami/scripts/liblog.sh @@ -30,7 +30,6 @@ stderr_print() { printf "%b\\n" "${*}" >&2 fi } - ######################## # Log message # Arguments: @@ -39,7 +38,14 @@ stderr_print() { # None ######################### log() { - stderr_print "${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}${*}" + local prefix="" + local color_bool="${BITNAMI_COLOR:-true}" + if [[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]]; then + prefix="${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}" + else + prefix="${MODULE:-} $(date "+%T.%2N ")" + fi + stderr_print "${prefix}${*}${RESET}" } ######################## # Log an 'info' message @@ -49,7 +55,12 @@ log() { # None ######################### info() { - log "${GREEN}INFO ${RESET} ==> ${*}" + local msg_color="" + local color_bool="${BITNAMI_COLOR:-true}" + if [[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]];then + msg_color="$GREEN" + fi + log "${msg_color}INFO ${RESET} ==> ${*}" } ######################## # Log message @@ -59,7 +70,12 @@ info() { # None ######################### warn() { - log "${YELLOW}WARN ${RESET} ==> ${*}" + local msg_color="" + local color_bool="${BITNAMI_COLOR:-true}" + if [[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]];then + msg_color="$YELLOW" + fi + log "${msg_color}WARN ${RESET} ==> ${*}" } ######################## # Log an 'error' message @@ -69,7 +85,12 @@ warn() { # None ######################### error() { - log "${RED}ERROR${RESET} ==> ${*}" + local msg_color="" + local color_bool="${BITNAMI_COLOR:-true}" + if [[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]];then + msg_color="$RED" + fi + log "${msg_color}ERROR${RESET} ==> ${*}" } ######################## # Log a 'debug' message @@ -81,15 +102,18 @@ error() { # None ######################### debug() { - # 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it - local bool="${BITNAMI_DEBUG:-false}" + local msg_color="" + local color_bool="${BITNAMI_COLOR:-true}" + if [[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]] ;then + msg_color="$MAGENTA" + fi # comparison is performed without regard to the case of alphabetic characters shopt -s nocasematch - if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then - log "${MAGENTA}DEBUG${RESET} ==> ${*}" + local debug_bool="${BITNAMI_DEBUG:-false}" + if [[ "$debug_bool" = 1 || "$debug_bool" =~ ^(yes|true)$ ]]; then + log "${msg_color}DEBUG${RESET} ==> ${*}" fi } - ######################## # Indent a string # Arguments: @@ -111,4 +135,4 @@ indent() { # shellcheck disable=SC2001 # Complex regex, see https://github.com/koalaman/shellcheck/wiki/SC2001#exceptions echo "$string" | sed "s/^/${indent_unit}/" -} +} \ No newline at end of file