My program doesn't have bugs. It just develops random features.

Legacy:Log File

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

To open a log window, launch UT200x with the command line option "-log".

Writing to the log file[edit]

The log file is generally the easiest and most straightforward of the writing functions. The log file is shared among all classes, and will be overwritten every time the game is started. In addition, no facility exists to read the log file from within Unrealscript, though it is easily readable with any text editor.

Note that writing to the log file actually writes to a buffer which is periodically written to the log file, so if the engine crashes with a GPF or similar error shortly after the log statement, it may not have made it into the actual log file. The engine will automatically write out anything left in the log buffer during a normal shutdown. To write to the log file, you can use one of two functions:


Log( ''Text'', ''Prefix'' );

The log function takes two arguments, though the second argument is optional. The first argument is a string and is the text that will be written into the log. You can put any variable type in here, and the function will automatically cast it into a string for you. The second argument is the prefix you would like to have for your log message. The prefix is a name variable, not a string, so it should be enclosed in single quotes and cannot contain spaces. If you omit a prefix, the prefix will default to 'ScriptLog'.


Warn( ''Text'' );

The Warn function is similar to log, but cannot take a prefix and also automatically provides a bit of information about itself. It will list the name of the thing that called it as well as the function and line it was called from. It will even tell you which class it was that the warning was set in, so if you make a call to a superclasses function and that function generates a warning, it will include the name of the superclass instead of the subclass.

Examples of Log and Warn[edit]

The usage of Log and Warn is fairly straightforward, but some examples are provided here to help illustrate the description.

class SomeClass extends Interaction;
function LogSample()
  local int i;
  local string Example;
  log( "First Message" );
  log( "Second Message", 'ExampleMsg' );
  warn( "Third Message" );
  Example = "Iterating Message";
  for ( i=0;i<5;i++ )
    log( Example$" Number "$I );

The example function above would produce the following output in the log file:

ScriptLog: First Message
ExampleMsg: Second Message
Warning: Someclass Package.InteractionMaster.SomeClass (Function SomeClass.LogSample:0048) Third Message
ScriptLog: Iterating Message Number 0
ScriptLog: Iterating Message Number 1
ScriptLog: Iterating Message Number 2
ScriptLog: Iterating Message Number 3
ScriptLog: Iterating Message Number 4

If you want to write to the log file, but do not want to write into the same log file as everything else, you can use a FileLog instead, which allows you to specify a filename but requires a bit more work to use.