LOGGER: added a first logging script and sourced it in all the needed scripts

This commit is contained in:
XargonWan 2024-01-04 09:26:42 +01:00
parent eab36a04dc
commit 28550e33ac
15 changed files with 64 additions and 0 deletions

View file

@ -4,6 +4,7 @@
# This script is getting the latest release notes from the wiki and add them to the appdata # This script is getting the latest release notes from the wiki and add them to the appdata
source automation_tools/version_extractor.sh source automation_tools/version_extractor.sh
source /app/libexec/logger.sh
# Fetch appdata version # Fetch appdata version
appdata_version=$(fetch_appdata_version) appdata_version=$(fetch_appdata_version)

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
save_migration() { save_migration() {
# Finding existing ROMs folder # Finding existing ROMs folder
if [ -d "$default_sd/retrodeck" ] if [ -d "$default_sd/retrodeck" ]

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
check_network_connectivity() { check_network_connectivity() {
# This function will do a basic check for network availability and return "true" if it is working. # This function will do a basic check for network availability and return "true" if it is working.
# USAGE: if [[ $(check_network_connectivity) == "true" ]]; then # USAGE: if [[ $(check_network_connectivity) == "true" ]]; then

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
compress_game() { compress_game() {
# Function for compressing one or more files to .chd format # Function for compressing one or more files to .chd format
# USAGE: compress_game $format $full_path_to_input_file # USAGE: compress_game $format $full_path_to_input_file

View file

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
source functions/functions.sh source functions/functions.sh
source /app/libexec/logger.sh
debug_dialog() { debug_dialog() {
# This function is for displaying commands run by the Configurator without actually running them # This function is for displaying commands run by the Configurator without actually running them

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
directory_browse() { directory_browse() {
# This function browses for a directory and returns the path chosen # This function browses for a directory and returns the path chosen
# USAGE: path_to_be_browsed_for=$(directory_browse $action_text) # USAGE: path_to_be_browsed_for=$(directory_browse $action_text)

View file

@ -12,6 +12,7 @@ source /app/libexec/patching.sh
source /app/libexec/post_update.sh source /app/libexec/post_update.sh
source /app/libexec/prepare_emulator.sh source /app/libexec/prepare_emulator.sh
source /app/libexec/presets.sh source /app/libexec/presets.sh
source /app/libexec/logger.sh
# Static variables # Static variables
rd_conf="/var/config/retrodeck/retrodeck.cfg" # RetroDECK config file path rd_conf="/var/config/retrodeck/retrodeck.cfg" # RetroDECK config file path

42
functions/logger.sh Normal file
View file

@ -0,0 +1,42 @@
# This script provides a logging function 'log' that can be sourced in other scripts.
# It logs messages to both the terminal and a specified logfile, allowing different log levels.
# The log function takes three parameters: log level, log message, and optionally the logfile. If no logfile is specified, it writes to retrodeck/logs/retrodeck.log
# Example usage:
# log w "foo" -> logs a warning with message foo in the default log file retrodeck/logs/retrodeck.log
# log e "bar" -> logs an error with message bar in the default log file retrodeck/logs/retrodeck.log
# log i "par" rekku.log -> logs an information with message in the specified log file inside the logs folder retrodeck/logs/rekku.log
log() {
local level="$1"
local message="$2"
local timestamp="$(date +[%Y-%m-%d\ %H:%M:%S])"
local logfile="${3:-$logs_folder/retrodeck.log}" # Use specified logfile or default to retrodeck.log
case "$level" in
w)
# Warning (yellow) for terminal, no color for log file
colored_message="\e[33m[WARN]\e[0m $message"
echo "$timestamp $colored_message" | tee -a >(sed $'s,\e\\[[0-9;]*[a-zA-Z],,g' >> "$logfile")
;;
e)
# Error (red) for terminal, no color for log file
colored_message="\e[31m[ERROR]\e[0m $message"
echo "$timestamp $colored_message" | tee -a >(sed $'s,\e\\[[0-9;]*[a-zA-Z],,g' >> "$logfile")
;;
i)
# Info (green) for terminal, no color for log file
colored_message="\e[32m[INFO]\e[0m $message"
echo "$timestamp $colored_message" | tee -a >(sed $'s,\e\\[[0-9;]*[a-zA-Z],,g' >> "$logfile")
;;
d)
# Debug (green) for both terminal and log file
colored_message="\e[32m[DEBUG]\e[0m $message"
echo "$timestamp $colored_message" | tee -a "$logfile"
;;
*)
# Default (no color)
echo "$timestamp $message" | tee -a "$logfile"
;;
esac
}

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
multi_user_set_default_dialog() { multi_user_set_default_dialog() {
chosen_user="$1" chosen_user="$1"
choice=$(zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="Yes" --extra-button="No" --extra-button="No and don't ask again" \ choice=$(zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="Yes" --extra-button="No" --extra-button="No and don't ask again" \

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
set_setting_value() { set_setting_value() {
# Function for editing settings # Function for editing settings
# USAGE: set_setting_value "$setting_file" "$setting_name" "$new_setting_value" "$system" "$section_name(optional)" # USAGE: set_setting_value "$setting_file" "$setting_name" "$new_setting_value" "$system" "$section_name(optional)"

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
prepare_emulator() { prepare_emulator() {
# This function will perform one of several actions on one or more emulators # This function will perform one of several actions on one or more emulators
# The actions currently include "reset" and "postmove" # The actions currently include "reset" and "postmove"

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/logger.sh
change_preset_dialog() { change_preset_dialog() {
# This function will build a list of all systems compatible with a given preset, their current enable/disabled state and allow the user to change one or more # This function will build a list of all systems compatible with a given preset, their current enable/disabled state and allow the user to change one or more
# USAGE: change_preset_dialog "$preset" # USAGE: change_preset_dialog "$preset"

View file

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
source /app/libexec/global.sh source /app/libexec/global.sh
source /app/libexec/logger.sh
# Arguments section # Arguments section

View file

@ -3,6 +3,7 @@
# VARIABLES SECTION # VARIABLES SECTION
source /app/libexec/global.sh source /app/libexec/global.sh
source /app/libexec/logger.sh
# DIALOG SECTION # DIALOG SECTION

View file

@ -4,6 +4,7 @@
# USAGE: /bin/bash retrodeck_function_wrapper.sh <function_name> <arg1> <arg2> ... # USAGE: /bin/bash retrodeck_function_wrapper.sh <function_name> <arg1> <arg2> ...
source /app/libexec/global.sh source /app/libexec/global.sh
source /app/libexec/logger.sh
# Check if a function was specified # Check if a function was specified
if [[ $# -lt 1 ]]; then if [[ $# -lt 1 ]]; then