AppStateESS / phpwebsite

phpWebSite Content Management System
Other
33 stars 39 forks source link

Configurable Log Facility #73

Open jtickle opened 11 years ago

jtickle commented 11 years ago

We need a logging manager that does more than just logMessage in Function.php. I need a standard inferface for logging that can be replaced and configured, so that I have the option of logging to a standard phpWebSite-formatted logfile, or to syslog, or to curl some notice to a remote machine (like Splunk or some such); the possibilities for logging are endless!

Also should be logging more than just errors and warnings. Need to be able to log users' activities in a general way across the site. Logging is a huge topic that we need to discuss and implement sooner than later.

┆Issue is synchronized with this Asana task

Stardog commented 11 years ago

I agree with you BUT I would like to get a settings module completed first so that core settings (like "What are you doing with error messages?") can be managed. So I am reassigning this to 1.8.2.

jtickle commented 11 years ago

Sounds good.

trf000 commented 11 years ago

I actually have an events log along with error, boost and security. just shows when someone edited a page, but was a huge help in determining if someone really did do something. Now I can see that log filling up quick on a large content site, but it would be helpful, and can be emptied from time to time.

jlbooker commented 11 years ago

So, let's start by listing out the various possibilities we can come up with, so that we can determine a common API around them. So far I have:

Anything else before we determine the elements these things have in common?

jtickle commented 11 years ago

You can log to pretty much anything in the world as long as your entry has a level (INFO, WARN, ERROR, DEBUG, etc) and a string. That string then should have a consistent format for the product (ie, Combined Log Format for HTTPD). Splunk works its magic because they have written all kinds of regexes to parse the log files produced by many different products, and it's a thing where once we have our format decided upon, we can make a regex for it.

We need to decide what log format we're going to use. I am thinking that we don't need to worry about things logged by the web server (IP, URI, response code). Maybe we are more concerned with File, Line, Message. We need to look inside our own software to figure out how that format is going to flow.

It's also possible that we have multiple logging formats for different things. For instance, our general log of "this application ran and had debug info" is probably going to necessitate a completely different format than "this module sent an email to this person."

Maybe the interface looks something like this: $log->log(new ApplicationLogEntry($this, 'message')); $log->log(new EmailLogEntry($this, $email->messageId, $email->to, $email->subject)); $log->log(new MyCustomLogFormat($whatever));

Once we've decided on a format for the "string" portion, it's just a matter of writing different log drivers:

jtickle commented 11 years ago

Also in terms of how the globally configured logger is passed into the application, please consider using the Module object. The Module is passed into every Controller upon instantiation, and it's a nice opportunity to do dependency injection.

$module->getLogger()->log(...);

And if the application developer wants a shortcut, they can then make interfaces like:

$module->log('...'); $module->emailLog('...');

the bodies of which are just $this->getLogger()->log(new ApplicationLog(...)) or some such.