LOGGER: potential fix for logs folder not being created

This commit is contained in:
XargonWan 2024-03-21 22:01:17 +01:00
parent 9596021616
commit 5570700867

View file

@ -2,34 +2,35 @@
# It logs messages to both the terminal and a specified logfile, allowing different log levels. # 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 # 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
# Type of log messages:
# log d - debug message: maybe in the future we can decide to hide them in main builds or if an option is toggled
# log i - normal informational message
# log w - waring: something is not expected but it's not a big deal
# log e - error: something broke
# Example usage: # Example usage:
# log w "foo" -> logs a warning with message foo in the default log file retrodeck/logs/retrodeck.log # 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 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 i "par" rekku.log -> logs an information with message in the specified log file inside the logs folder retrodeck/logs/rekku.log
# if [ "${log_init:-false}" = false ]; then
# logs_folder=${logs_folder:-"/tmp"}
# create_dir $logs_folder
# touch "$logs_folder/retrodeck.log"
# # exec > >(tee "$logs_folder/retrodeck.log") 2>&1 # this is broken, creates strange artifacts and corrupts the log file
# log_init=true
# fi
# this is a one off otherwise it would be logging every time this function is called
# if retrodeck folder variable is not yet initialized
if [ -z "${rdhome}" ]; then if [ -z "${rdhome}" ]; then
tmp_logs_folder="/tmp/rdlogs" tmp_logs_folder="/tmp/rdlogs"
logs_folder="$tmp_logs_folder" logs_folder="$tmp_logs_folder"
create_dir "$logs_folder" create_dir "$logs_folder"
# if the log folder is not existing
elif [ ! -d "$rd_logs_folder" ]; then
rd_logs_folder="$rdhome/logs"
create_dir "$rd_logs_folder"
elif [ ! -z "${rdhome}" ] && [ -d "$tmp_logs_folder" ]; then elif [ ! -z "${rdhome}" ] && [ -d "$tmp_logs_folder" ]; then
cp -f "$tmp_logs_folder/retrodeck.log" "$logs_folder/retrodeck.log" cp -f "$tmp_logs_folder/retrodeck.log" "$logs_folder/retrodeck.log"
rm -rf "$tmp_logs_folder" rm -rf "$tmp_logs_folder"
fi fi
rd_logs_folder="$rdhome/logs"
if [ ! -d "$rd_logs_folder" ]; then
# this is a one off otherwise it would be logging every time this function is called
create_dir "$rd_logs_folder"
fi
log() { log() {
# exec > >(tee "$logs_folder/retrodeck.log") 2>&1 # this is broken, creates strange artifacts and corrupts the log file # exec > >(tee "$logs_folder/retrodeck.log") 2>&1 # this is broken, creates strange artifacts and corrupts the log file