IRC-Bot icon indicating copy to clipboard operation
IRC-Bot copied to clipboard

Add a logging mechanism

Open DanielSiepmann opened this issue 14 years ago • 11 comments

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.

DanielSiepmann avatar Jan 11 '12 22:01 DanielSiepmann

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.

super3 avatar Jan 12 '12 01:01 super3

Of course that's right!

DanielSiepmann avatar Jan 12 '12 06:01 DanielSiepmann

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.

NanoSector avatar Jan 09 '15 14:01 NanoSector

It does? I have never had a problem with the current log system.

JackBlower avatar Jan 09 '15 14:01 JackBlower

The bot randomly saves or doesn't save log files for me. I can't find the logic behind it.

NanoSector avatar Jan 09 '15 14:01 NanoSector

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.

JackBlower avatar Jan 09 '15 14:01 JackBlower

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.

NanoSector avatar Jan 09 '15 14:01 NanoSector

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

NanoSector avatar Jan 09 '15 15:01 NanoSector

Oh, seems PHP does buffering by itself. Well okay then.

http://php.net/manual/en/function.stream-set-write-buffer.php

NanoSector avatar Jan 09 '15 15:01 NanoSector

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.

JackBlower avatar Jan 09 '15 15:01 JackBlower

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.

NanoSector avatar Jan 09 '15 16:01 NanoSector