Add a logging mechanism
There is already a mechanism for logging. But I think it's better to define a Logger for this task, that is assigned to a bot OR a connection.
So everything, the bot, commands, are able to log something.
We should probably implement something to make the logging optional. No use to have a bunch of log files, when you don't really need them.
Of course that's right!
If we do log stuff, we should probably use a combination of a log manager (with buffer) and these functions: http://php.net/manual/en/function.register-shutdown-function.php http://php.net/manual/en/function.file-put-contents.php We should make it save the log file every day or so as well, and not an enormous buffer either (so no filling up RAM). Because a buffer should be a buffer and not a temporary storage before being saved to a file.
I'm looking into this as we speak, because lets face it; the current log system doesn't really work. It fails to save files half the time.
Why use a log manager with buffer? Because rapidly logging items to a file kills I/O performance and generally isn't nice for hard drives anyway.
It does? I have never had a problem with the current log system.
The bot randomly saves or doesn't save log files for me. I can't find the logic behind it.
It opens a file handle and then writes to it there and then, which means no memory buffer or anything unless that has been changed recently?
You can even tail -f the logs.
EDIT: You seem to contradict yourself by saying that the bot uses a lot of memory, but doesn't because it thrashes the disk, I'm a little confused.
It opens a file handle, but forgets to write the file I guess.
Either way, I'm making a LogManager to help maintain it and separate all this from the main Bot.php file.
Quote: EDIT: You seem to contradict yourself by saying that the bot uses a lot of memory, but doesn't because it thrashes the disk, I'm a little confused.
The bot doesn't use a lot of memory, contrary. I mean we should flush the log buffer once in a while so it doesn't eat up all the memory. We're trashing the disk by writing every line to the log file, as soon as it is passed to bot->log().
Oh, seems PHP does buffering by itself. Well okay then.
http://php.net/manual/en/function.stream-set-write-buffer.php
Logging instantly is a common feature though, take a look at irssi's logs, they write as the lines are said. Perhaps a better logging solution is needed, that could be toggled between thrash and cache 'n' write.
I'll make both an option; on slow disks a big buffer can be used for a decent speedup, on faster disks where no problems are met the lines are fwrite'd instantly.