Logging can be configured in the World Editor, see Section 4.4, 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.
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:
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.