mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2024-11-21 21:45:39 +00:00
LOGGER: added a first logging script and sourced it in all the needed scripts
This commit is contained in:
parent
eab36a04dc
commit
28550e33ac
|
@ -4,6 +4,7 @@
|
|||
# This script is getting the latest release notes from the wiki and add them to the appdata
|
||||
|
||||
source automation_tools/version_extractor.sh
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
# Fetch appdata version
|
||||
appdata_version=$(fetch_appdata_version)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
save_migration() {
|
||||
# Finding existing ROMs folder
|
||||
if [ -d "$default_sd/retrodeck" ]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
check_network_connectivity() {
|
||||
# This function will do a basic check for network availability and return "true" if it is working.
|
||||
# USAGE: if [[ $(check_network_connectivity) == "true" ]]; then
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
compress_game() {
|
||||
# Function for compressing one or more files to .chd format
|
||||
# USAGE: compress_game $format $full_path_to_input_file
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source functions/functions.sh
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
debug_dialog() {
|
||||
# This function is for displaying commands run by the Configurator without actually running them
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
directory_browse() {
|
||||
# This function browses for a directory and returns the path chosen
|
||||
# USAGE: path_to_be_browsed_for=$(directory_browse $action_text)
|
||||
|
|
|
@ -12,6 +12,7 @@ source /app/libexec/patching.sh
|
|||
source /app/libexec/post_update.sh
|
||||
source /app/libexec/prepare_emulator.sh
|
||||
source /app/libexec/presets.sh
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
# Static variables
|
||||
rd_conf="/var/config/retrodeck/retrodeck.cfg" # RetroDECK config file path
|
||||
|
|
42
functions/logger.sh
Normal file
42
functions/logger.sh
Normal 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
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
multi_user_set_default_dialog() {
|
||||
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" \
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
set_setting_value() {
|
||||
# Function for editing settings
|
||||
# USAGE: set_setting_value "$setting_file" "$setting_name" "$new_setting_value" "$system" "$section_name(optional)"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
prepare_emulator() {
|
||||
# This function will perform one of several actions on one or more emulators
|
||||
# The actions currently include "reset" and "postmove"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
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
|
||||
# USAGE: change_preset_dialog "$preset"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /app/libexec/global.sh
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
# Arguments section
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# VARIABLES SECTION
|
||||
|
||||
source /app/libexec/global.sh
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
# DIALOG SECTION
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
# USAGE: /bin/bash retrodeck_function_wrapper.sh <function_name> <arg1> <arg2> ...
|
||||
|
||||
source /app/libexec/global.sh
|
||||
source /app/libexec/logger.sh
|
||||
|
||||
# Check if a function was specified
|
||||
if [[ $# -lt 1 ]]; then
|
||||
|
|
Loading…
Reference in a new issue