Skip to content

Commit

Permalink
Add config to fully disable tw server logging
Browse files Browse the repository at this point in the history
Closed #49

keeps the crash logs and all other logs
but not the main application logs
  • Loading branch information
ChillerDragon committed Feb 16, 2025
1 parent b825efd commit 1f4313f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/include/crashsave_loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ logfile="$LOGS_PATH_FULL_TW/${CFG_SRV_NAME}_$(date +%F_%H-%M-%S)${CFG_LOG_EXT}"
start_ts_slug=$(date '+%Y-%m-%d_%H-%M-%S')
start_ts=$(date '+%Y-%m-%d %H:%M:%S')

log_cmd=''
if is_cfg CFG_ENABLE_LOGGING
then
log_cmd="logfile $logfile"
fi

export COMMIT_HASH
if ! COMMIT_HASH="$(get_commit)"
then
err "failed to get commit hash"
exit 1
fi
run_cmd="$CFG_ENV_RUNTIME ./$CFG_BIN 'exec autoexec.cfg;logfile $logfile;#sid:$SERVER_UUID:loop_script'"
run_cmd="$CFG_ENV_RUNTIME ./$CFG_BIN 'exec autoexec.cfg;$log_cmd;#sid:$SERVER_UUID:loop_script'"
log "running:"
tput bold
echo "$run_cmd"
Expand Down
8 changes: 7 additions & 1 deletion lib/include/gdb_loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ fi
gdb_tmp_log_header="$p/full_gdb.header.txt.tmp"
gdb_tmp_log_gdb="$p/full_gdb.gdb.txt.tmp"

log_cmd=''
if is_cfg CFG_ENABLE_LOGGING
then
log_cmd="logfile $logfile"
fi

read -rd '' GDB_CMD << EOF
$CFG_ENV_RUNTIME gdb -ex='set confirm off' \
-ex='set pagination off' \
Expand All @@ -114,7 +120,7 @@ $CFG_ENV_RUNTIME gdb -ex='set confirm off' \
$custom_gdb \
$gdb_corefile_cmd \
-ex=quit --args \
./$CFG_BIN "exec autoexec.cfg;logfile $logfile;#sid:$SERVER_UUID:loop_script"
./$CFG_BIN "exec autoexec.cfg;$log_cmd;#sid:$SERVER_UUID:loop_script"
EOF
git_patches="$(get_applied_git_patches)"
start_ts=$(date '+%Y-%m-%d %H:%M:%S')
Expand Down
1 change: 1 addition & 0 deletions lib/include/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def_var 'CFG_ENV_BUILD' 'env_build' 'source $SCRIPT_ROOT/lib/env_san.sh;' '(.*=.
# shellcheck disable=SC2016
def_var 'CFG_ENV_RUNTIME' 'env_runtime' 'source $SCRIPT_ROOT/lib/env_san.sh;' '(.*=.*|.*;$|)'
def_var 'CFG_LOG_EXT' 'logfile_extension' ".log" ''
def_var 'CFG_ENABLE_LOGGING' 'enable_logging' "1" '(0|no|off|false|1|yes|on|true)'
def_var 'CFG_AUTO_CLEANUP_OLD_LOCAL_DATA' 'auto_cleanup_old_local_data' "0" '(0|no|off|false|1|yes|on|true)'
def_var 'CFG_GITPATH_ANTIBOT' 'gitpath_antibot' "" ''
def_var 'CFG_LOG_DDOS' 'log_ddos' "0" '(0|no|off|false|1|yes|on|true)'
Expand Down
7 changes: 7 additions & 0 deletions show_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ do
fi
done

if ! is_cfg CFG_ENABLE_LOGGING
then
err "Error: logging is not enabled"
err " set enable_logging=1 in your server.cnf"
exit 1
fi

if [ "$arg_print" == "1" ]
then
if [ "$arg_logpath" == "" ]
Expand Down
11 changes: 9 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ else # teeworlds
err "failed to get commit hash"
exit 1
fi
run_cmd="$CFG_ENV_RUNTIME nohup ./$CFG_BIN \"exec autoexec.cfg;#sid:$SERVER_UUID\" > $logfile 2>&1 &"

logredirect='&> /dev/null'
if is_cfg CFG_ENABLE_LOGGING
then
logredirect="&> $logfile"
fi

run_cmd="$CFG_ENV_RUNTIME nohup ./$CFG_BIN \"exec autoexec.cfg;#sid:$SERVER_UUID\" $logredirect &"
if [ "$arg_is_interactive" == "1" ]
then
run_cmd="$CFG_ENV_RUNTIME ./$CFG_BIN \"exec autoexec.cfg;#sid:$SERVER_UUID\""
Expand All @@ -129,7 +136,7 @@ else # teeworlds
tput sgr0
bash -c "set -euo pipefail;$run_cmd"

if [ "$arg_logs" == "1" ] && [ "$arg_is_interactive" == "0" ]
if [ "$arg_logs" == "1" ] && [ "$arg_is_interactive" == "0" ] && is_cfg CFG_ENABLE_LOGGING
then
show_log_file "$logfile"
fi
Expand Down

0 comments on commit 1f4313f

Please sign in to comment.