Chapter 14. Logging the Output

Logging can be configured in the World Editor, see Section 4.4, “Logging”, but there are also functions to start and stop logging from the command line.

Logging is controlled with the $world->logfile function. The first argument specifies the path to the file where the output is saved. If the file already exists, new text will be appended to it.

The file name is passed throught strftime(), so you can log to different files depending on the date and/or time. Also, you can use %Kw in the file name and it will be replaced by the name of the World. And the string %Kc is replaced by the name of the character used in auto-login (see Section 4.1, “General”). (If auto-login was not used, then %Kc is replaced by an empty string.)

The second argument, if present, controls the format of the timestamp. If you do not want a timestamp, then do not pass a second argument, pass only the file name. This timestamp argument is a string with control codes. Each control code will be substituted by a part of the time or date. This sequences are the ones of the strftime() C function, so see its man page for the list of control sequences.

Here's an example that turns on logging, with a timestamp that shows the date and time:

Example 14.1. Enabling logging
$world->logfile('/home/bob/mud/mudlog.txt', '%b/%d %H:%M:%S> ')

To turn off logging, just call logfile with no arguments.

There are functions to write arbitrary text to the log file: $world->writetolog and $world->echonlandlog.