Add numerical debug levels

This commit is contained in:
Juno Takano 2024-07-18 11:23:24 -03:00
parent 4566955440
commit ae206ccc3e
4 changed files with 46 additions and 15 deletions

View file

@ -1,9 +1,13 @@
0.4.1 2024-07-14: Fixes "Cancel" option not exiting on package resolution 0.5.0 2024-07-18: "Decide in editor" package conflict resolution strategy
Fixes whitespace preventing package list matches on "remove all" Drop pipefail shell option for dash compatibility
Add numerical debug levels to the log utility function
Check for shell option support before setting
0.4.1 2024-07-14: Fix "Cancel" option not exiting on package resolution
Fix whitespace preventing package list matches on "remove all"
0.4.0 2024-07-14: "Add/remove all from configuration" resolution strategy 0.4.0 2024-07-14: "Add/remove all from configuration" resolution strategy
0.3.1 2024-07-13: Refactor, new docs page, make cache refresh lazier 0.3.1 2024-07-13: Refactor, new docs page, make cache refresh lazier
0.3.0 2024-07-11: "Enter packages to install/uninstall" resolution strategy 0.3.0 2024-07-11: "Enter packages to install/uninstall" resolution strategy
0.2.1 2024-07-10: Rename package_resolution.sh, document package conflicts 0.2.1 2024-07-10: Rename package_resolution.sh, document package conflicts
0.2.0 2024-07-10: Implement "uninstall/instal all" package resolution strategies 0.2.0 2024-07-10: Implement "uninstall/instal all" package resolution strategies
0.1.1 2024-07-07: Handle missing tori.conf and invalid installation root path 0.1.1 2024-07-07: Handle missing tori.conf and invalid installation root path
0.1.0 2024-07-07: Added configuration parsing 0.1.0 2024-07-07: Add configuration parsing

View file

@ -29,12 +29,8 @@ scan_packages() {
user_packages="$(get_user_packages)" user_packages="$(get_user_packages)"
if [ "$system_packages" = "$user_packages" ]; then if [ "$system_packages" = "$user_packages" ]; then
log debug "packages match" log debug "Packages match"
else else
log debug "packages mismatch"
log debug "system:\n$system_packages"
log debug "user:\n$user_packages"
log user "System and configuration packages differ" log user "System and configuration packages differ"
resolve_packages resolve_packages
fi fi

View file

@ -4,12 +4,42 @@ log() {
local level="$1" local level="$1"
local message="$2" local message="$2"
if [ "$level" = fatal ]; then print_user_message() {
echo "[tori] $(date "+%H:%M:%S"): $message" 1>&2 echo "[tori] $(date "+%H:%M:%S"): $1" 1>&2
elif [ "$level" = user ]; then }
echo "[tori] $(date "+%H:%M:%S"): $message" 1>&2
elif [ -n "$DEBUG" ] && [ "$level" = debug ]; then print_debug_message() {
echo "$(date "+%H:%M:%N") $message" 1>&2 echo "$(date "+%H:%M:%N") $1" 1>&2
}
if [ -z "$DEBUG" ]; then
DEBUG=3
elif ! echo "$DEBUG" | grep -q '^[[:number:]]$'; then
echo "[log] Warning: DEBUG should always be set to a number. Assuming DEBUG=3 (warn)"
DEBUG=3
fi
if [ -z "$DEBUG_DISABLED_WARNING" ] && [ "$DEBUG" -eq 0 ]; then
echo "[log] Warning: Setting DEBUG=0 disables all logging except for user messages"
echo " Use a value beween 1 (fatal) and 5 (debug). The default level is 3 (warn)"
DEBUG_DISABLED_WARNING=1
elif [ "$DEBUG" -gt 5 ]; then
echo "[log] Warning: Assuming DEBUG maximum level of 5 (debug) over provided level $DEBUG"
DEBUG=5
fi
if [ "$level" = user ]; then
print_user_message "$message"
elif [ "$DEBUG" -ge 1 ] && [ "$level" = fatal ]; then
print_user_message "$message"
elif [ "$DEBUG" -ge 2 ] && [ "$level" = error ]; then
print_user_message "$message"
elif [ "$DEBUG" -ge 3 ] && [ "$level" = warn ]; then
print_user_message "$message"
elif [ "$DEBUG" -ge 4 ] && [ "$level" = info ]; then
print_debug_message "$message"
elif [ "$DEBUG" -ge 5 ] && [ "$level" = debug ]; then
print_debug_message "$message"
fi fi
} }
@ -21,7 +51,7 @@ set_opts() {
if set -o | grep -q "^$opt[[:space:]]"; then if set -o | grep -q "^$opt[[:space:]]"; then
set "${sign}o" "$opt" set "${sign}o" "$opt"
log debug "[set_opts] Set: $(set -o | grep -q "^$opt[[:space:]]")" log debug "[set_opts] Set: $(set -o | grep "^$opt[[:space:]]")"
else else
log fatal "Unsupported shell: no $opt option support" log fatal "Unsupported shell: no $opt option support"
return 1 return 1

1
tori
View file

@ -11,6 +11,7 @@ main() {
# os-independent state # os-independent state
DEBUG=$DEBUG DEBUG=$DEBUG
DEBUG_DISABLED_WARNING=
## user input ## user input
argument="$1" argument="$1"