Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a logging mechanism #9

Open
DanielSiepmann opened this issue Jan 11, 2012 · 11 comments
Open

Add a logging mechanism #9

DanielSiepmann opened this issue Jan 11, 2012 · 11 comments

Comments

@DanielSiepmann
Copy link
Collaborator

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.

@ghost ghost assigned DanielSiepmann Jan 11, 2012
@super3
Copy link
Owner

super3 commented Jan 12, 2012

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.

@DanielSiepmann
Copy link
Collaborator Author

Of course that's right!

@NanoSector
Copy link
Contributor

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.

@JackBlower
Copy link

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

@NanoSector
Copy link
Contributor

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

@JackBlower
Copy link

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.

@NanoSector
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

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

@JackBlower
Copy link

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.

@NanoSector
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants