We've been using bootstrap.php to have a basic PHP file run parts of some content-sync from a plugin we've written.

The sync is run from cron and this works great.

BUT - when the sync runs from the bootstrapped file - there are no logging info stored. I.e. the sync code works fine, but nothing is logged to: craft/storage/runtime/logs/<pluginname>.log - when triggering the sync from within the CP as a full-craft request, logging works fine.

Is there a way to get the bootstrap app to setup logging, so that logging from my plugin would work?


If you're doing it from a custom bootstrap script, you'd need to do something like this for plugin logging to work:

$craft = require '../craft/app/bootstrap.php';

MyPlugin::log('My Message', LogLevel::Error);
  • Ah - I did the loadPlugins, but not craft()->end(); was missing, thanks Brad! – gromgull Apr 23 '15 at 7:10
  • Logs don't get flushed until the onEndRequest event fires, which craft()->end() will do for you. – Brad Bell Apr 23 '15 at 16:40
  • not really related to this question - but sometimes I have longer running processes - and I'd like to flush the logs sooner - is there something you can call to flush them mid-request? – gromgull Apr 24 '15 at 13:27
  • @gromgull - Yup... wanna post that as a new question? – Brad Bell Apr 24 '15 at 14:43

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.