Updated logging function and added LOG_TOPIC environment variable

This commit is contained in:
2026-02-27 19:57:20 -06:00
parent cfed476096
commit 382a096c1b
4 changed files with 47 additions and 26 deletions

View File

@@ -5,10 +5,19 @@
touch "$LOG_FILE"
mosquitto_pub -h 127.0.0.1 -p 1883 -t "$TOPIC" "SaveLogStart=1"
mosquitto_sub -h 127.0.0.1 -p 1883 -q 0 -t "$TOPIC" | while IFS="=" read -r key value
log_to_file() {
printf "%s\n" "$1" >> "$LOG_FILE"
}
# Subscribe and wait for log entries
mosquitto_sub -h 127.0.0.1 -t "$LOG_TOPIC" | while read -r line
do
case "$key" in
"SaveLog") printf "%s\n" "$value" >>"$LOG_FILE" ;;
esac
# The line will look like: SaveLog=[2026-...] [INFO] ...
# We strip the "SaveLog=" prefix
msg_content="${line#SaveLog=}"
if [ -n "$msg_content" ]; then
log_to_file "$msg_content"
fi
done