Following on from part 1, we now have our logger class being called as and where we need it. And as long as we always intend to use the same class, we’re OK.
But at some point, we’ll no doubt be rolling out a LoggerV2 class. And as Logger is tied in to our existing codebase, that’s a whole lot of changes we need to make.
So I came up with a simple idea. Symlink the Logger class!
Instead of
\Core\Logger::getInstance()
I instead call
\Core\DefaultLogger::getInstance()
and add in an empty class of
class DefaultLogger extends Logger { }
Now, when we get to the point of updating, I change the DefaultLogger to extend off LoggerV2 instead, and all default functionality across the site is changed.
I’m not sure if this has a proper pattern name (I don’t think it’s an adapter), but if it has, hopefully someone will share it in the comments to I can get a better idea of how this technique can fit along side other patterns. Until then, you’re welcome to use the Chris’s Fantabulous Symlink Pattern!
So back to Monolog. We have the class where and when we need it, now lets make it do something useful.