I have a Craft Plugin that is a logging library I want to use in other plugins I develop, but I don't want it to be a dependancy in these other plugins. Is there a nice, space efficient way in Craft to do something like below? I don't want to have to wrap every call in an if statement:

# If WatchTower isn't installed... don't explode please!!!

My plugin seems to stop processing and redirect to the current page if it isn't installed. Thanks!


You could write a wrapper log method that's abstracts the check away so you only have to do it once. The update your code to use the wrapper.

That method could just use craft()->plugins->getPlugin('pluginHandle') to see if the target plugin is installed and enabled. Craft will auto-load the plugin's services, so you don't need to check specifically for them.

  • That's a good idea thanks Brad. I could override BasePlugin::log() in these other plugins and have it use WatchTower or gracefully fall back to use BasePlugin::log() if WatchTower isn't installed. That's fine for my use but not ideal if another developer was using it though. I'll think on it some more. Thanks for your time!
    – JamesNZ
    May 17 '16 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.