Skip to content

Some functions of liblog.sh log component are enhanced #76245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 27, 2025

Conversation

huangjc7
Copy link
Contributor

Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 [email protected]

Description of the change

Added errorX function, which exits with non-zero value after execution
Added BITNAMI_COLOR method, which can control the color switch

Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 <[email protected]>
@github-actions github-actions bot added redis-cluster triage Triage is needed labels Jan 14, 2025
@github-actions github-actions bot requested a review from javsalgar January 14, 2025 16:18
@carrodher carrodher added verify Execute verification workflow for these changes in-progress labels Jan 14, 2025
@github-actions github-actions bot removed the triage Triage is needed label Jan 14, 2025
@github-actions github-actions bot removed the request for review from javsalgar January 14, 2025 17:09
@github-actions github-actions bot requested a review from gongomgra January 14, 2025 17:09
@huangjc7
Copy link
Contributor Author

huangjc7 commented Jan 15, 2025

@gongomgra VIB verification failed. What is the reason?

Copy link
Contributor

@gongomgra gongomgra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I have added some comments to your changes

reset_color=""
fi
log "${msg_color}ERROR${reset_color} ==> ${*}"
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice this is a logging library, and that running exit 1 here doesn't make much sense. Please remove this method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not disregard this comment, please.

Comment on lines 41 to 52
log() {
stderr_print "${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}${*}"
local prefix=""
local suffix=""
local color_check="${BITNAMI_COLOR:-true}"
if [[ "$color_check" =~ ^(yes|true)$ ]]; then
prefix="${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}"
suffix="${RESET}"
else
prefix="${MODULE:-} $(date "+%T.%2N ")"
fi
stderr_print "${prefix}${*}${suffix}"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a couple of minor changes in this method would make it clear, what do you think?

  • Rename color_check to color_bool.
  • Update if logic to match the one in line 29 of this file due to the reasons in line 25.

Comment on lines 63 to 64
local color_check="${BITNAMI_COLOR:-true}"
if ! [[ "$color_check" =~ ^(yes|true)$ ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update if condition format, and please implement the logic the other way around: if true then set colors

msg_color=""
reset_color=""
fi
log "${msg_color}INFO ${reset_color} ==> ${*}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply use ${RESET} here (for all use cases).

local msg_color="$YELLOW"
local reset_color="$RESET"
local color_check="${BITNAMI_COLOR:-true}"
if ! [[ "$color_check" =~ ^(yes|true)$ ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same

Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 <[email protected]>
Copy link
Contributor

@gongomgra gongomgra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Please check the pending comments and also update the conditionals on booleans variables to match the if structure in line 88 (check for 1 OR yes|true):

if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]: then
    ...
fi

Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 <[email protected]>
@huangjc7
Copy link
Contributor Author

Thanks for the update. Please check the pending comments and also update the conditionals on booleans variables to match the if structure in line 88 (check for 1 OR yes|true):

if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]: then
    ...
fi

@gongomgra The new one has been submitted and supports BITNAMI_COLOR=1. I would like to explain that for simple and short logic, using && or || may be more concise, and omitting if can also improve readability. If complex logic is generated later, I will re-use if to write

@huangjc7 huangjc7 requested a review from gongomgra February 2, 2025 09:55
@huangjc7
Copy link
Contributor Author

huangjc7 commented Feb 6, 2025

@gongomgra All the modified contents have been submitted in the final version. Please review them. Thank you.

Copy link
Contributor

@gongomgra gongomgra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! I have added new comments, and there are still some pending comments from previous reviews. Can you please check all of them?

if ! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then
printf "%b\\n" "${*}" >&2
fi
! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]] && printf "%b\\n" "${*}" >&2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be that we are more used to the previous conditional structure than this one, but please revert this change for all occurrences.

else
prefix="${MODULE:-} $(date "+%T.%2N ")"
fi
stderr_print "${prefix}${*}${suffix}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the suffix variable is not necessary here. We can simply use ${RESET} in stderr_print and avoid allocating memory for it (even if it is almost free). Please consider this review for the rest of the functions with the same structure.

reset_color=""
fi
log "${msg_color}ERROR${reset_color} ==> ${*}"
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not disregard this comment, please.

Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 <[email protected]>
@huangjc7
Copy link
Contributor Author

@gongomgra New changes have been submitted, please check
Some questions that need to be discussed have also been submitted

Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 <[email protected]>
Copy link
Contributor

@gongomgra gongomgra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for applying all the feedback! It is only pending to remove the errorX() method. The rest look good to me

Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 <[email protected]>
@huangjc7
Copy link
Contributor Author

@gongomgra Submitted, please check

Copy link
Contributor

@gongomgra gongomgra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one of my teammates noticed another minor change. Could you implement it for all your updated methods?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include the additional options for the checks that are already present in other parts of the file

shopt -s nocasematch

@huangjc7
Copy link
Contributor Author

Sorry, one of my teammates noticed another minor change. Could you implement it for all your updated methods?

@gongomgra shopt -s nocasematch is effective globally, and I did not find any problems in my test.
1740207460846

Copy link
Contributor

@gongomgra gongomgra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@gongomgra gongomgra merged commit e952c9d into bitnami:main Feb 27, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
redis-cluster solved verify Execute verification workflow for these changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants