Custom logging extension

I’m looking for advice about extension architecture. Old logging subsystem is already deleted, so new extension has to be built from scratch and without any kind of backward compatibility or data loss fear.

Task essence: I’ve intranet system with mandatory authentication where it’s necessary to log certain actions. At first it was planned to log only database table changes. And as long as we’ve used only ActiveRecord approach, it was enough to use modified behavior.

Then we’ve added requirement for authentication logging and implemented it using the same database table. But the table was growing more and more fat. In addition some database queries where changed from AR to DAO (less overhead, sometimes easier to work with the result), also where added some many-to-many relations and transactions. In addition we’ve got some actions we must log where database interaction is no involved at all.

So I’ve came to a conclusion, that logging has to be moved to a separate extension or component. What’s the best and optimal way for it? Extension? Module? Component?

There’s already 3 databases in the application (main mysql, additional mysql, remote postgresql) and I don’t like the idea of adding one more for logs. I’m planning to keep logs in the main database tables, naming them by pattern log_modulename to separate different logs from each other.

You should consider using an existing library, like monolog.

You can use following extension to utilize PSR compatible logger like Monolog:

https://github.com/yii1tech/psr-log