Skip to content

Commit 2304da4

Browse files
committed
refactor: update logging mechanism and streamline log file handling in entrypoint.sh
1 parent 196e161 commit 2304da4

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

Yolk/entrypoint.sh

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,24 @@ RUNTIME_MODE="${RUNTIME_MODE:-wine}"
3030

3131
# Logging
3232
LOG_DIR="${CONTAINER_HOME}/logs"
33-
LOG_FILE="${LOG_DIR}/sbox-server.log"
34-
ERROR_LOG="${LOG_DIR}/sbox-error.log"
3533
UPDATE_LOG="${LOG_DIR}/sbox-update.log"
34+
SBOX_LOG="${SBOX_INSTALL_DIR}/logs/sbox-server.log"
3635

3736
# ============================================================================
3837
# LOGGING FUNCTIONS
3938
# ============================================================================
4039
mkdir -p "${LOG_DIR}"
4140

4241
log_info() {
43-
echo "[$(date '+%Y-%m-%d %H:%M:%S')] INFO: $*" | tee -a "${LOG_FILE}"
42+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] INFO: $*"
4443
}
4544

4645
log_warn() {
47-
echo "[$(date '+%Y-%m-%d %H:%M:%S')] WARN: $*" | tee -a "${LOG_FILE}" >&2
46+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] WARN: $*" >&2
4847
}
4948

5049
log_error() {
51-
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $*" | tee -a "${ERROR_LOG}" >&2
50+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $*" >&2
5251
}
5352

5453
# ============================================================================
@@ -369,19 +368,19 @@ start_metrics_loop() {
369368
(
370369
# Wait for the server log to appear.
371370
local waited=0
372-
while [ ! -f "${LOG_FILE}" ] && [ "${waited}" -lt 30 ]; do
371+
while [ ! -f "${SBOX_LOG}" ] && [ "${waited}" -lt 30 ]; do
373372
sleep 1
374373
waited=$((waited+1))
375374
done
376375

377376
while true; do
378377
sleep "${interval}"
379-
[ -f "${LOG_FILE}" ] || continue
378+
[ -f "${SBOX_LOG}" ] || continue
380379

381380
# Count players by tallying connect/disconnect lines since boot.
382381
local connects disconnects
383-
connects=$(grep -c "is connected$" "${LOG_FILE}" 2>/dev/null || echo 0)
384-
disconnects=$(grep -c "disconnected\|dropped\|timed out" "${LOG_FILE}" 2>/dev/null || echo 0)
382+
connects=$(grep -c "is connected$" "${SBOX_LOG}" 2>/dev/null || echo 0)
383+
disconnects=$(grep -c "disconnected\|dropped\|timed out" "${SBOX_LOG}" 2>/dev/null || echo 0)
385384
player_count=$(( connects - disconnects ))
386385
[ "${player_count}" -lt 0 ] && player_count=0
387386

@@ -518,10 +517,8 @@ run_sbox() {
518517
log_error "Linux native runtime mode is not yet supported; please switch to wine or proton while this is being worked on and tested"
519518
exit 1
520519
else # default to wine
521-
# Redirect stdout/stderr to the log BEFORE exec so the log pipe is
522-
# inherited by Wine. stdin stays as the TTY so console input works.
523-
# exec replaces the shell so Wine becomes the terminal owner (no child process).
524-
exec > >(tee -a "${LOG_FILE}") 2>&1
520+
# S&Box writes its own logs to ${SBOX_INSTALL_DIR}/logs/sbox-server.log.
521+
# Pass wine stdout/stderr straight to the console with no extra pipe.
525522
exec env "${launch_env[@]}" wine "${SBOX_SERVER_EXE}" "${args[@]}"
526523
fi
527524

0 commit comments

Comments
 (0)