Skip to content

Instantly share code, notes, and snippets.

@MattMcFarland
Last active August 1, 2023 10:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MattMcFarland/4c2f5cdd4657e91239cf7285b5d3b726 to your computer and use it in GitHub Desktop.
Save MattMcFarland/4c2f5cdd4657e91239cf7285b5d3b726 to your computer and use it in GitHub Desktop.
Run X4 Foundations in debug mode with timestamped file names so you don't lose them.

Run X4 Foundations in debug mode.

The handy script below (x4-debug.bat) can be used as a shortcut to start x4 in debug mode. You get:

  • All debug messages turned on
  • All debug logs sent to a timestamped file, so you dont lose anything

Setup

Copy paste the code in the file below, then update the value for X4_EXE_PATH - change it to wherever X4.exe is located. Your debug logs will be available in the Documents\Egosoft\X4 Foundations\ folder.

Advanced Usage

Consider using a log analysis tool like glogg which can help you sort, filter, and find data in the logs.

@echo off
rem !!--- please change this to where your game is installed. do not add any spacing aroud the equals operator
rem !!--- set X4_EXE_PATH="Location of your X4.exe"
set X4_EXE_PATH="%PROGRAMFILES(X86)%\Steam\steamapps\common\X4 Foundations\X4.exe"
rem !!--- set the date and time for logfile year-month-day__hh-mm-ss
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%__%datetime:~8,2%-%datetime:~10,2%-%datetime:~12,2%
echo "Date & Time test = %datetime% year-month-day__hh-mm-ss"
rem stores a value like `x4-game-2018-12-10__11-04-11.log` - to be passed in -logfile
set LOG_FILE_NAME=x4-game-%datetime%.log
rem stores a value like `x4-script-2018-12-10__11-04-11.log` - to be passed in -scriptlogfile
set SCRIPT_LOG_FILE_NAME=x4-script-%datetime%.log
set "exec=%X4_EXE_PATH% -logfile %LOG_FILE_NAME% -scriptlogfile %SCRIPT_LOG_FILE_NAME%"
rem execution phase, first we log out the command, if any of the variables are blank, make sure you dont have whitespace around any of the variables
echo "Executing %X4_EXE_PATH% -debug all -logfile %LOG_FILE_NAME% -scriptlogfile %SCRIPT_LOG_FILE_NAME%"
start "" %X4_EXE_PATH% -showfps -debug all -logfile %LOG_FILE_NAME% -scriptlogfile %SCRIPT_LOG_FILE_NAME%
@MattMcFarland
Copy link
Author

Big thanks to a mysterious person on x4 forums for sharing with me the l10n issue 👍

@JanPanthera
Copy link

good work... but it isn't scriptlogfile it is scriptlogfiles :-)
start "" %X4_EXE_PATH% -showfps -debug all -logfile %LOG_FILE_NAME% -scriptlogfiles <---- %SCRIPT_LOG_FILE_NAME%

@Patola
Copy link

Patola commented May 26, 2019

What are the debug outputs, besides "all"?

@UniTrader
Copy link

jan12342203

Scriptlogfiles are named and put in a subfolder within the Script. The Command is
<debug_to_file name="'FILENAME'" directory="'DIRECTORYNAME'" text="'Line to be logged'"/>
you can omit the Directory to put it directly in the logs, but its not a single file you can name via startup parameter, its possibly lots of them.

@kuertee
Copy link

kuertee commented Jun 28, 2022

What are the debug outputs, besides "all"?

according to this wiki entry (https://www.egosoft.com:8444/confluence/display/X4WIKI/h2odragon%27s+HOWTO-hackx4f#debug-log) the other filters are:
error, general, scripts, scripts_verbose, economy_verbose, combat, and savegame

replied so that i don't have to keep looking for the list. :D

@IonutDanNica
Copy link

I've made a fork of this functionality into Powershell, with some minor enhancements, it is available here:
https://gist.github.com/IonutDanNica/da07ed87f479626e7847c6f8a4e5be7a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment