2

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?

1 Answer 1

3

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';

craft()->plugins->loadPlugins();
MyPlugin::log('My Message', LogLevel::Error);
craft()->end();
5
  • Ah - I did the loadPlugins, but not craft()->end(); was missing, thanks Brad!
    – gromgull
    Commented Apr 23, 2015 at 7:10
  • Logs don't get flushed until the onEndRequest event fires, which craft()->end() will do for you.
    – Brad Bell
    Commented Apr 23, 2015 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
    Commented Apr 24, 2015 at 13:27
  • @gromgull - Yup... wanna post that as a new question?
    – Brad Bell
    Commented Apr 24, 2015 at 14:43
  • craftcms.stackexchange.com/questions/9446/… :)
    – gromgull
    Commented Apr 25, 2015 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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