logging over mqtt, TODO: Write log handler

This commit is contained in:
Sonja Rivierien
2026-02-27 16:26:27 -06:00
parent 276b84b9aa
commit 3d766f28d8
3 changed files with 65 additions and 24 deletions

View File

@@ -2,20 +2,34 @@
# shellcheck shell=ash
# --- Configuration ---
LOG_FILE="/recalbox/share/system/logs/es_event_monitor.log"
DEBUG_MODE=1
REMOTE_BASE="saves:gamepi-tv"
. /recalbox/share/system/config/savesync/savesync.conf
# --- MQTT Publish Function ---
mqtt_publish() {
local msg="$1"
}
# --- Logger Function ---
log() {
local level="$1"
local msg="$2"
mkdir -p "$(dirname "$LOG_FILE")"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local log_line="[$timestamp] [$level] $msg"
printf "%s\n" "$log_line" >> "$LOG_FILE" 2>/dev/null
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
local timestamp
local level="$1"
local msg="$2"
mkdir -p "$(dirname "$LOG_FILE")"
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local log_line="[$timestamp] [$level] $msg"
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event "SaveLog=${log_line}"
# printf "%s\n" "$log_line" >> "$LOG_FILE" 2>/dev/null
[ "$DEBUG_MODE" -eq 1 ] && printf "%s\n" "$log_line"
}
send_continue() {
mosquitto_pub -h 127.0.0.1 -p 1883 -t /Recalbox/EmulationStation/Event "SaveContinue=1"
}
log "INFO" "--- ES Event Daemon Started ---"
@@ -31,7 +45,8 @@ do
"GamePath")
this_game_path="$value"
# Logic: Change .gba/.zip to .srm
this_save_path="${value%.*}.srm"
this_save_path="$(echo "${value%.*}.srm" | sed 's|roms|saves|')"
this_backup_path="$(dirname "$this_save_path" | sed 's|roms|archives|')"
;;
"Action") this_action="$value" ;;
"State")
@@ -52,7 +67,8 @@ do
if [ "$local_size" -lt "$remote_size" ]; then
log "WARN" "Cloud save is LARGER ($remote_size vs $local_size). Restoring..."
rclone copyto "$remote_full" "$this_save_path"
mkdir -p "$(dirname "${this_backup_path}")"
rclone copyto "$remote_full" "$this_save_path" --backup-dir "$this_backup_path"
else
log "INFO" "Local save is safe. Running update check..."
rclone update "$remote_full" "$this_save_path"
@@ -67,7 +83,7 @@ do
rclone update "$this_save_path" "$REMOTE_BASE/$this_system_id/"
log "INFO" "Sync Complete."
fi
# Reset variables for the next event block
this_system_id=""; this_game_path=""; this_save_path=""; this_action=""
;;