-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
Added BITNAMI_COLOR method, which can control the color switch Signed-off-by: huangjc7 <[email protected]>
@gongomgra VIB verification failed. What is the reason? |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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}" | ||
} |
There was a problem hiding this comment.
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
tocolor_bool
. - Update
if
logic to match the one in line 29 of this file due to the reasons in line 25.
local color_check="${BITNAMI_COLOR:-true}" | ||
if ! [[ "$color_check" =~ ^(yes|true)$ ]]; then |
There was a problem hiding this comment.
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} ==> ${*}" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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]>
There was a problem hiding this 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]>
@gongomgra The new one has been submitted and supports |
@gongomgra All the modified contents have been submitted in the final version. Please review them. Thank you. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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]>
@gongomgra New changes have been submitted, please check |
Added BITNAMI_COLOR method, which can control the color switch Signed-off-by: huangjc7 <[email protected]>
There was a problem hiding this 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]>
@gongomgra Submitted, please check |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
@gongomgra |
There was a problem hiding this 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!
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