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?


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

  • 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")? – Lindsey D Jun 9 '15 at 21:25
  • Yeah, it would affect all plugins (and Craft!). Can't think of a way around it without getting super hacky. – Brad Bell Jun 9 '15 at 21:30
  • 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)? – Lindsey D Jun 9 '15 at 21:31
  • Also, this may be more configurable in Yii 2/Craft 3 - still need to look into it. – Brad Bell Jun 9 '15 at 21:31
  • Yii::trace only gets logged when devMode is enabled. It's where 95% of the extra devMode logging info comes from. – Brad Bell Jun 9 '15 at 21:33

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.