mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2024-11-22 14:05:39 +00:00
LOGGER: enhancements
This commit is contained in:
parent
878e3e41ca
commit
90cf770298
|
@ -156,6 +156,7 @@ if [[ ! -f "$rd_conf" ]]; then
|
|||
log i "RetroDECK config file initialized. Contents:\n"
|
||||
log i "$(cat "$rd_conf")"
|
||||
conf_read # Load new variables into memory
|
||||
tmplog_merger
|
||||
|
||||
# If the config file is existing i just read the variables
|
||||
else
|
||||
|
@ -169,6 +170,7 @@ else
|
|||
fi
|
||||
|
||||
conf_read
|
||||
tmplog_merger
|
||||
|
||||
# Verify rdhome is where it is supposed to be.
|
||||
if [[ ! -d $rdhome ]]; then
|
||||
|
@ -177,6 +179,7 @@ else
|
|||
new_home_path=$(directory_browse "RetroDECK folder location")
|
||||
set_setting_value $rd_conf "rdhome" "$new_home_path" retrodeck "paths"
|
||||
conf_read
|
||||
tmplog_merger
|
||||
prepare_emulator "retrodeck" "postmove"
|
||||
prepare_emulator "all" "postmove"
|
||||
conf_write
|
||||
|
|
|
@ -7,12 +7,20 @@
|
|||
# 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
|
||||
|
||||
exec > >(tee -a "$logs_folder/retrodeck.log") 2>&1
|
||||
if [ "${log_init:-false}" = false ]; then
|
||||
logs_folder=${logs_folder:-"/tmp"}
|
||||
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
|
||||
|
||||
log() {
|
||||
|
||||
# exec > >(tee "$logs_folder/retrodeck.log") 2>&1 # this is broken, creates strange artifacts and corrupts the log file
|
||||
|
||||
local level="$1"
|
||||
local message="$2"
|
||||
local timestamp="$(date +[%Y-%m-%d\ %H:%M:%S])"
|
||||
local timestamp="$(date +[%Y-%m-%d\ %H:%M:%S.%3N])"
|
||||
local colorize_terminal
|
||||
|
||||
# Use specified logfile or default to retrodeck.log
|
||||
|
@ -90,3 +98,20 @@ log() {
|
|||
echo "$log_message" >> "$logfile"
|
||||
|
||||
}
|
||||
|
||||
# This function is merging the temporary log file into the actual one
|
||||
tmplog_merger() {
|
||||
|
||||
# Check if /tmp/retrodeck.log exists
|
||||
if [ -e "/tmp/retrodeck.log" ]; then
|
||||
|
||||
# Sort both temporary and existing log files by timestamp
|
||||
sort -k1,1n -k2,2M -k3,3n -k4,4n -k5,5n "/tmp/retrodeck.log" "$logs_folder/retrodeck.log" > "$logs_folder/merged_logs.tmp"
|
||||
|
||||
# Move the merged logs to replace the original log file
|
||||
mv "$logs_folder/merged_logs.tmp" "$logs_folder/retrodeck.log"
|
||||
|
||||
# Remove the temporary file
|
||||
rm "/tmp/retrodeck.log"
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue