Game Development Community

Logfile name switch

by Adam Beaumont · 12/10/2003 (9:40 am) · 1 comments

This might already be possible (if so please let me know how!) but in my defence I couldn't find any other solution.

Sometimes when running a dedicated server and connecting client on the same machine (for testing) it is useful to be able to specify the name of the logfile that each process dumps to (i.e. server.log and client.log). This code change adds a switch to the command line that does just this:

-logfile

where the -logfile switch should appear before any -log switches. This is because the logfile can currently only be specified before it is created and not mid run.(tho this probably wouldn't be too difficult to do).

The files that need changing are:

engine\console\console.cc
main.cs

Console.cc
Around line 177 add the variable that is going to hold our new logfile name.
// This is the name we will use for the logfile
StringTableEntry gLogFileName;

Add a console function to set it (around line 200)
ConsoleFunction( setLogFileName, void, 2, 2, "(string text)"
               "Set the log file name")
{
	gLogFileName = StringTable->insert(argv[1]);
};

Initialise it to the default value in the init() function, somewhere around line 232
// Initialise logfile name
gLogFileName = StringTable->insert(defLogFileName);

Then in the log function change (around line 367)
consoleLogFile.open(defLogFileName, FileStream::ReadWrite);
to
consoleLogFile.open(gLogFileName, FileStream::ReadWrite);

and similarly in the setLogMode function (around line 908)
consoleLogFile.open(defLogFileName, FileStream::Write);
to
consoleLogFile.open(gLogFileName, FileStream::Write);

main.cs
Find the part of the code that process command line arguments (about line 46). Add another case to the switch statement above the -log entry (so make it the first case):
case "-logfile":
         $argUsed[$i]++;
         if ($hasNextArg)
         {
				setLogFileName($nextArg);
				$argUsed[$i+1]++;
            $i++;
			}
			else
				error("Error: Must specify a log file name");

And that should be it. When starting simply add the -logfile switch with the name of the logfile u want to use.

I haven't had any problems with this so far but if anyone does find anything then please tell me. I'm still pretty new to Torque programming so there may well be something in there that breaks all known rules of decency ! If so let me know.

#1
07/26/2004 (7:06 pm)
Just implemented this, and it work like a charm just what I wanted. I did make a slight change and defaulted the logfile name if one isn't specified.