Chapter 14. Logging the Output

A useful feature of KildClient is it hability to log all the output from the MUD, as shown in the screen, so that you can retrieve it later.

The output is saved in a file you specify. ANSI color codes are not saved, but otherwise the output is identical.

It is possible to prefix each line with a timestamp, so you can see when each line was received. You can specify the format of this timestamp.

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 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.