added a mechanism di disable debug messages

work related to https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=2713
This commit is contained in:
Guillaume Raffy 2023-12-06 10:25:01 +01:00
parent 9def80af12
commit e3c4dba850
1 changed files with 16 additions and 2 deletions

View File

@ -15,32 +15,46 @@ readonly COLOR_RESET='\033[0m'
RETURNCODE_SUCCESS=0 RETURNCODE_SUCCESS=0
RETURNCODE_ERROR=1 RETURNCODE_ERROR=1
DEFAULT_PYTHON_PATH='/usr/bin/python3'
PYTHON_PATH=''
readonly LOG_LEVEL_ERROR=0
readonly LOG_LEVEL_WARNING=1
readonly LOG_LEVEL_INFO=2
readonly LOG_LEVEL_DEBUG=3
LOG_LEVEL=$LOG_LEVEL_INFO
log() log()
{ {
local log_type="$1" # 'debug', 'info', 'warning' or 'error' local log_type="$1" # 'debug', 'info', 'warning' or 'error'
local message="$2" local message="$2"
local message_color='' local message_color=''
local message_level=''
case "$log_type" in case "$log_type" in
'error') 'error')
message_color="$COLOR_RED" message_color="$COLOR_RED"
message_level="$LOG_LEVEL_ERROR"
;; ;;
'warning') 'warning')
message_color="$COLOR_YELLOW" message_color="$COLOR_YELLOW"
message_level="$LOG_LEVEL_WARNING"
;; ;;
'info') 'info')
message_color="$COLOR_BLUE" message_color="$COLOR_BLUE"
message_level="$LOG_LEVEL_INFO"
;; ;;
'debug') 'debug')
message_color="$COLOR_PURPLE" message_color="$COLOR_PURPLE"
message_level="$LOG_LEVEL_DEBUG"
;; ;;
*) *)
echo "unexpected log type $log_type" echo "unexpected log type $log_type"
exit "$RETURNCODE_ERROR" exit "$RETURNCODE_ERROR"
esac esac
printf "%b : %s\n" "${message_color}${log_type}${COLOR_RESET}" "$message" if [ "$message_level" -le "$LOG_LEVEL" ]
then
printf "%b : %s\n" "${message_color}${log_type}${COLOR_RESET}" "$message"
fi
} }
replace_in_file() replace_in_file()