Game Development Community

Console.log rotate

by Lee Latham · in Torque Game Engine · 03/04/2008 (1:30 am) · 4 replies

How would one go about saving console.log's in a rotation? For example, append a number to the name, so that you never lose log data?

I guess I'm wondering if anyone's run across a resource or forum post that describes how to do it. My C++ is not adequate to the task.

But I keep losing logs I need because I am too quick to restart my server :-}

#1
03/04/2008 (11:08 am)
I believe this would work:

In engine/code/console.cc, find the method: void setLogMode(S32 newMode)
and replace the line that opens the console.log file:
consoleLogFile.open(defLogFileName, FileStream::Write);

with:

Platform::LocalTime lt;
   Platform::getLocalTime(lt);
   char fn[132];
   dSprintf(fn, 131, "%s_%d%02d%02d_%02d%02d%02d.log", "console", 1900+lt.year, 1+lt.month, lt.monthday, lt.hour, lt.min, lt.sec);
   consoleLogFile.open(fn, FileStream::Write);

This will create a file name like: console_20080304_130045.log (encoding the date and time of opening).

An improvement would be to parse the defLogFileName for the "console" and the ".log" parts rather than just hardcoding it as above.
#3
03/05/2008 (9:14 am)
I see that this isn't adequate for the logging modes where the file is opened and closed each write. (That is, there are other console creation sections of code for other modes. This just handles perhaps the most common access methods.)
#4
03/05/2008 (2:40 pm)
Thanks Matthew!