ID:1141143
 
(See the best response by Jemai1.)
So you can set world.log to a file() object to have world.log output to a file instead, but then you lose host output in unix or daemon or what have you.

So my question is, which is more efficient in terms of memory and speed:

Keeping a huge text variable, and adding to it, saving that text variable periodically or just on shutdown (but you lose it all on a crash).

Keeping a list, adding each line of the log to the list, save the list periodically or just on shutdown.

Calling text2file() everytime you want to log something.

Some other way I'm not aware of?

Thanks.
Best response
You can do
file("logfile.txt") << "text"

to append a text to a file.

This is pretty much how world.log is used. Except setting world.log will make error messages sent to that file.

So you can do something like this
var/gamelog_file = file("gamelog.txt")

proc/gamelog(text)
gamelog_file << "\[[time2text(world.realtime)]]: [text]"
In response to Jemai1
Jemai1 wrote:
You can do
> file("logfile.txt") << "text"
>

to append a text to a file.

This is pretty much how world.log is used. Except setting world.log will make error messages sent to that file.

So you can do something like this
> var/gamelog_file = file("gamelog.txt")
>
> proc/gamelog(text)
> gamelog_file << "\[[time2text(world.realtime)]]: [text]"
>


Thanks for the information, greatly appreciated.
Pretty much any other approach than writing to file will result in probable resource exhaustion. Of those, maintaining a file as Jemai1 notes is probably best.

Ideally you won't log inside tight loops on a release build anyway, only on a #DEBUG build, as such your logging isn't a performance issue worth worrying about. When debugging, all performance requirements should probably go out of the window, in favour of verifying the functionality is correct.