mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2025-04-10 19:15:12 +00:00
LOGGER: fixed colorization
This commit is contained in:
parent
00a8552788
commit
c1bb13ceb7
|
@ -22,6 +22,21 @@
|
||||||
# The function auto-detects if the shell is sh and avoids colorizing the output in that case.
|
# The function auto-detects if the shell is sh and avoids colorizing the output in that case.
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
|
|
||||||
|
# Define and export log color environment variables for ES-DE
|
||||||
|
export logcolor_debug="\033[32m[DEBUG]"
|
||||||
|
export logcolor_error="\033[31m[ERROR]"
|
||||||
|
export logcolor_warn="\033[33m[WARN]"
|
||||||
|
export logcolor_info="\033[37m[INFO]"
|
||||||
|
export logcolor_default="\033[37m[LOG]"
|
||||||
|
|
||||||
|
# Define and export log prefix environment variables for ES-DE
|
||||||
|
export logprefix_debug="[DEBUG]"
|
||||||
|
export logprefix_error="[ERROR]"
|
||||||
|
export logprefix_warn="[WARN]"
|
||||||
|
export logprefix_info="[INFO]"
|
||||||
|
export logprefix_default="[LOG]"
|
||||||
|
|
||||||
# Exit immediately if logging_level is "none"
|
# Exit immediately if logging_level is "none"
|
||||||
if [[ $logging_level == "none" ]]; then
|
if [[ $logging_level == "none" ]]; then
|
||||||
return
|
return
|
||||||
|
@ -37,10 +52,10 @@ log() {
|
||||||
local caller="${FUNCNAME[1]:-FWORK}"
|
local caller="${FUNCNAME[1]:-FWORK}"
|
||||||
caller="${caller^^}" # Convert to uppercase
|
caller="${caller^^}" # Convert to uppercase
|
||||||
|
|
||||||
# Check if the shell is sh to avoid colorization
|
# # Check if the shell is sh to avoid colorization
|
||||||
if [ "${SHELL##*/}" = "sh" ]; then
|
# if [ "${SHELL##*/}" = "sh" ]; then
|
||||||
colorize_terminal=false
|
# colorize_terminal=false
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# Internal function to check if the message should be logged
|
# Internal function to check if the message should be logged
|
||||||
should_log() {
|
should_log() {
|
||||||
|
@ -57,24 +72,24 @@ log() {
|
||||||
# Define colors based on the message level
|
# Define colors based on the message level
|
||||||
case "$level" in
|
case "$level" in
|
||||||
d)
|
d)
|
||||||
color="\e[32m[DEBUG]"
|
color="${logcolor_debug:-\033[32m[DEBUG]}"
|
||||||
prefix="[DEBUG]"
|
prefix="${logprefix_debug:-[DEBUG]}"
|
||||||
;;
|
;;
|
||||||
e)
|
e)
|
||||||
color="\e[31m[ERROR]"
|
color="${logcolor_error:-\033[31m[ERROR]}"
|
||||||
prefix="[ERROR]"
|
prefix="${logprefix_error:-[ERROR]}"
|
||||||
;;
|
;;
|
||||||
w)
|
w)
|
||||||
color="\e[33m[WARN]"
|
color="${logcolor_warn:-\033[33m[WARN]}"
|
||||||
prefix="[WARN]"
|
prefix="${logprefix_warn:-[WARN]}"
|
||||||
;;
|
;;
|
||||||
i)
|
i)
|
||||||
color="\e[34m[INFO]"
|
color="${logcolor_info:-\033[37m[INFO]}"
|
||||||
prefix="[INFO]"
|
prefix="${logprefix_info:-[INFO]}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
color="\e[37m[LOG]"
|
color="${logcolor_default:-\033[37m[LOG]}"
|
||||||
prefix="[LOG]"
|
prefix="${logprefix_default:-[LOG]}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue