Game Development Community

A different way to monitor console.log under Windows

by Shaderman · 05/11/2009 (1:56 pm) · 9 comments

When I began to work with Torque engines, I got used to opening the console in game now an then to see what's going on. One day I found the function enableWinConsole() by accident and used it from that day. This is a very useful function but it sucks to get that little window placed near the game window again and again...

Why not have something like the Unix tail command to monitor the console.log file? You've probably tried that yourself already and found out that the console.log file is locked and inaccessible for other programs.

Only 3 lines of code need to be changed to allow concurrently reading of the log file by a tail program like Tail for Win32 (free) in TGEA, TGE or TGB (and I guess in T3D as well).

Screenshot (with a colored keyword example):
shaderman.com/Torque/misc/tail.png

Here's what you need to do:

Open the file engine/source/platform/Win32winFileio.cpp (TGEA 1.8.1) or engine/platform/Win32winFileio.cc (TGE 1.5.2 and TGB 1.7.4), search for "create the appropriate type of file", go down some lines and change the 3rd parameter of these CreateFile() function calls from 0 to FILE_SHARE_READ:

case Write:
      handle = (void *)CreateFile(fname,
         GENERIC_WRITE,
         FILE_SHARE_READ,
         NULL,
         CREATE_ALWAYS,
         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
         NULL);
      break;
   case ReadWrite:
      handle = (void *)CreateFile(fname,
         GENERIC_WRITE | GENERIC_READ,
         FILE_SHARE_READ,
         NULL,
         OPEN_ALWAYS,
         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
         NULL);
      break;
   case WriteAppend:
      handle = (void *)CreateFile(fname,
         GENERIC_WRITE,
         FILE_SHARE_READ,
         NULL,
         OPEN_ALWAYS,
         FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
         NULL);
      break;

I hope you like it :)

Shaderman

#1
05/11/2009 (3:16 pm)
Wow very nice Resource.
#3
05/12/2009 (2:01 am)
Thank you Stefan, I'm using this from now on.
#4
05/12/2009 (2:04 am)
perfect! always missed "tail"-ing while on windows! thanks a lot for sharing!
#5
05/12/2009 (8:38 am)
Ah cool, I like it!
#6
05/12/2009 (11:02 am)
Smart, thanks!
#7
05/12/2009 (9:30 pm)
You're welcome :)
#8
10/02/2009 (2:14 pm)
i think that the shared read access to the log file is a must in the engine..., thanks.
#9
02/17/2012 (10:30 pm)
In T3D 1.2, you'll find it under platformWin32, winFileio.cpp

about line # 251 is where you'll find "// create the appropriate type of file"

and for me, it was lines #266 and 275 which had to be changed from 0 -> FILE_SHARE_READ.