Rethinking watchdog(): logging in Kohana 3
Continuing this exploration of logging solutions used in various projects, let's look at logging in Kohana 3.
While Monolog and log4php share a mostly common logging model of a frontal Logger object instantiated as many times as needed to supply different logging channels, in which log events are Processed/Filtered then written out by Handlers/Writers, Kohana builds upon a simpler model, which can be summarized by three patterns:
- Singleton: there is only one instance of the Kohana
Log
- Observer:
Log_Writer
instances are attached (and detached) to(/from) the logger instance and handle events they are interested in based on their own configuration. Much like a Drupal hook, all writer instances receive eachLog
event - Delegation: the
Log
exposes awrite()
to trigger the buffered writing, but does not implement it itself, but delegates to theLog_Writer
objects to perform it. Buffered logging control is aLog
property, not aLog_Writer
property.