Reputation: 21895
In my PHP web application, I want to have the ability to perform the following logging operations:
I am trying to decide on the better achitecture. I have two in mind. Which of these is the better one? I'm open to others as well.
EDIT Here's what I'm probably going to go with.
Upvotes: 1
Views: 52
Reputation: 116110
I would use neither. I'd use a design that implements the same log method for each implementation. So it looks like Design #1, but a little different.
Create descendants for each type of log you have and override the log method.
Then, create a factory for specific purposes, so:
That way, when you need to log a query, you just call
QueryLoggerFactory->getInstance()->log($query);
And nowhere in your application you need to call a specific method. If you decide you want to store the query in the database too, you just instantiate a different logger in your factory. You can even instantiate a logger that logs itself to two other loggers, so you can store errors in FireBug and in the database. Or you can instantiate a void logger that doesn't log anything.
Upvotes: 2