Answers.Body: <p>If you're doing it from a custom bootstrap script, you'd need to do something like this for plugin logging to work:</p>
  
  <pre><code>$craft = require '../craft/app/bootstrap.php';
  
  craft()-&gt;plugins-&gt;loadPlugins();
  MyPlugin::log('My Message', LogLevel::Error);
  craft()-&gt;end();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T07:10:49.783Z
Answers.Text: Ah - I did the loadPlugins, but not `craft()->end();` was missing, thanks Brad!
Answers.UserDisplayName: gromgull
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T16:40:37.680Z
Answers.Text: Logs don't get flushed until the `onEndRequest` event fires, which `craft()->end()` will do for you.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T13:27:39.107Z
Answers.Text: 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?
Answers.UserDisplayName: gromgull
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T14:43:12.273Z
Answers.Text: @gromgull - Yup... wanna post that as a new question?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-25T15:50:15.653Z
Answers.Text: http://craftcms.stackexchange.com/questions/9446/flushing-logs-halfway-through-a-request :)
Answers.UserDisplayName: gromgull
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-22T20:39:22.167Z
Answers.LastActivityDate: 2015-04-22T20:39:22.167Z
Answers.UserDisplayName: Brad Bell
Body: <p>We've been using bootstrap.php to have a basic PHP file run parts of some content-sync from a plugin we've written. </p>
  
  <p>The sync is run from cron and this works great. </p>
  
  <p>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: <code>craft/storage/runtime/logs/&lt;pluginname&gt;.log</code> - when triggering the sync from within the CP as a full-craft request, logging works fine. </p>
  
  <p>Is there a way to get the bootstrap app to setup logging, so that logging from my plugin would work?</p>
  
Tags: <plugin-development><bootstrap-craft><logging>
Title: Logging from Bootstrap mode?
ThreadText: # Logging from Bootstrap mode?
  
  (Asked by: username_0 on 2015-04-22)
  
  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?
  
  **Tags:** plugin-development, bootstrap-craft, logging
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-22. Score: 3 | Accepted answer
  
  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();
  
  ```
  
  > **Comments:**
  > **username_0**: Ah - I did the loadPlugins, but not `craft()->end();` was missing, thanks username_1!  
  > **username_1**: Logs don't get flushed until the `onEndRequest` event fires, which `craft()->end()` will do for you.  
  > **username_0**: 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?  
  > **username_1**: @username_0 - Yup... wanna post that as a new question?  
  > **username_0**: http://craftcms.stackexchange.com/questions/9446/flushing-logs-halfway-through-a-request :)  
  
  ---
  
  