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

CC BY-SA 3.0
2015-04-23T07:10:49.783Z
Ah - I did the loadPlugins, but not `craft()->end();` was missing, thanks Brad!
gromgull
CC BY-SA 3.0
2015-04-23T16:40:37.680Z
Logs don't get flushed until the `onEndRequest` event fires, which `craft()->end()` will do for you.
Brad Bell
CC BY-SA 3.0
2015-04-24T13:27:39.107Z
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
CC BY-SA 3.0
2015-04-24T14:43:12.273Z
@gromgull - Yup... wanna post that as a new question?
Brad Bell
CC BY-SA 3.0
2015-04-25T15:50:15.653Z
http://craftcms.stackexchange.com/questions/9446/flushing-logs-halfway-through-a-request :)
gromgull
CC BY-SA 3.0
2015-04-22T20:39:22.167Z
2015-04-22T20:39:22.167Z
Brad Bell
<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>

<plugin-development><bootstrap-craft><logging>
Logging from Bootstrap mode?
# 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/.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 Brad!  
> **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 :)  

---

