Answers.Body: <p>By default a full stack trace will only be assembled and logged if an exception is thrown (which is what you're looking at in your 2nd example) mainly for performance reasons - cycling through the backtrace and assembling all of that info is a relatively expensive operation.</p>
  
  <p>Standard calls to <code>MyPlugin::log</code> or <code>Craft::log</code> will get a partial backtrace added to each message.  The depth of that is controlled by the <code>YII_TRACE_LEVEL</code> PHP constant, which Craft sets to 3 by default.</p>
  
  <p>If you want to have them log deeper into the trace, set that to a higher number in your public index.php file, just be aware of the performance implications.</p>
  
  <p>There is some discussions of that constant here in the Yii docs: <a href="http://www.yiiframework.com/doc/guide/1.1/en/topics.logging#logging-context-information">http://www.yiiframework.com/doc/guide/1.1/en/topics.logging#logging-context-information</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-09T21:25:47.820Z
Answers.Text: Very interesting! So if I were to make that change in my index.php, it would affect **all** plugins? Is it possible to trigger the logging _as an exception_ (instead of as "plugin")?
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-09T21:30:04.467Z
Answers.Text: Yeah, it would affect all plugins (and Craft!). Can't think of a way around it without getting super hacky.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-09T21:31:38.293Z
Answers.Text: Last question... In the Yii docs you link to, I see a reference to `Yii::trace`. Is that something that Craft passes through (and/or would it be useful in this case)?
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-09T21:31:53.950Z
Answers.Text: Also, this may be more configurable in Yii 2/Craft 3 - still need to look into it.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-09T21:33:01.173Z
Answers.Text: `Yii::trace` only gets logged when devMode is enabled.  It's where 95% of the extra devMode logging info comes from.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-09T21:22:24.757Z
Answers.LastActivityDate: 2015-06-09T21:22:24.757Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm using <code>MyPlugin::log</code> to separate the errors for my plugin. However, I'm only able to log a simple message using this technique.</p>
  
  <p>Is it possible to have that output the <strong>full stack trace</strong>?</p>
  
  <p>Here's what I'm getting (note the general format)...</p>
  
  <pre><code>2015/06/09 20:41:42 [error] [plugin] My example error message.
  in /craft/app/etc/plugins/BasePlugin.php (65)
  in /craft/plugins/businesslogic/services/BusinessLogicService.php (194)
  in /craft/plugins/businesslogic/controllers/BusinessLogic_ActivitiesController.php (47)
  </code></pre>
  
  <p>But here's what I <strong>want</strong> (again, note the general format)...</p>
  
  <pre><code>2015/06/09 20:39:25 [error] [exception.CException] exception 'CException' with message 'Craft\BusinessLogic_ActivitiesController and its behaviors do not have a method or closure named "handleError".' in /craft/app/framework/base/CComponent.php:266
  Stack trace:
  #0 /craft/plugins/businesslogic/controllers/BusinessLogic_ActivitiesController.php(47): CComponent-&gt;__call('handleError', Array)
  #1 /craft/plugins/businesslogic/controllers/BusinessLogic_ActivitiesController.php(47): Craft\BusinessLogic_ActivitiesController-&gt;handleError()
  #2 /craft/app/framework/web/actions/CInlineAction.php(49): Craft\BusinessLogic_ActivitiesController-&gt;actionUpdate()
  </code></pre>
  
  <p>How do I get the #0, #1, #2, etc. to show up?</p>
  
Tags: <plugin-development><logging><error-handling>
Title: How can I get a full stack trace in my custom plugin log?
ThreadText: # How can I get a full stack trace in my custom plugin log?
  
  (Asked by: username_0 on 2015-06-09)
  
  I'm using `MyPlugin::log` to separate the errors for my plugin. However, I'm only able to log a simple message using this technique.
  
  Is it possible to have that output the **full stack trace**?
  
  Here's what I'm getting (note the general format)...
  
  ```
  2015/06/09 20:41:42 [error] [plugin] My example error message.
  in /craft/app/etc/plugins/BasePlugin.php (65)
  in /craft/plugins/businesslogic/services/BusinessLogicService.php (194)
  in /craft/plugins/businesslogic/controllers/BusinessLogic_ActivitiesController.php (47)
  
  ```
  
  But here's what I **want** (again, note the general format)...
  
  ```
  2015/06/09 20:39:25 [error] [exception.CException] exception 'CException' with message 'Craft\BusinessLogic_ActivitiesController and its behaviors do not have a method or closure named "handleError".' in /craft/app/framework/base/CComponent.php:266
  Stack trace:
  #0 /craft/plugins/businesslogic/controllers/BusinessLogic_ActivitiesController.php(47): CComponent->__call('handleError', Array)
  #1 /craft/plugins/businesslogic/controllers/BusinessLogic_ActivitiesController.php(47): Craft\BusinessLogic_ActivitiesController->handleError()
  #2 /craft/app/framework/web/actions/CInlineAction.php(49): Craft\BusinessLogic_ActivitiesController->actionUpdate()
  
  ```
  
  How do I get the #0, #1, #2, etc. to show up?
  
  **Tags:** plugin-development, logging, error-handling
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-06-09. Score: 5 | Accepted answer
  
  By default a full stack trace will only be assembled and logged if an exception is thrown (which is what you're looking at in your 2nd example) mainly for performance reasons - cycling through the backtrace and assembling all of that info is a relatively expensive operation.
  
  Standard calls to `MyPlugin::log` or `Craft::log` will get a partial backtrace added to each message. The depth of that is controlled by the `YII_TRACE_LEVEL` PHP constant, which Craft sets to 3 by default.
  
  If you want to have them log deeper into the trace, set that to a higher number in your public index.php file, just be aware of the performance implications.
  
  There is some discussions of that constant here in the Yii docs: <http://www.yiiframework.com/doc/guide/1.1/en/topics.logging#logging-context-information>
  
  > **Comments:**
  > **username_0**: Very interesting! So if I were to make that change in my index.php, it would affect **all** plugins? Is it possible to trigger the logging _as an exception_ (instead of as "plugin")?  
  > **username_1**: Yeah, it would affect all plugins (and Craft!). Can't think of a way around it without getting super hacky.  
  > **username_0**: Last question... In the Yii docs you link to, I see a reference to `Yii::trace`. Is that something that Craft passes through (and/or would it be useful in this case)?  
  > **username_1**: Also, this may be more configurable in Yii 2/Craft 3 - still need to look into it.  
  > **username_1**: `Yii::trace` only gets logged when devMode is enabled.  It's where 95% of the extra devMode logging info comes from.  
  
  ---
  
  