8

I have a plugin returning json from a controller action using $this->returnJson(...).

Works great in production, but when devMode = true, the json is invalidated because Craft is still dumping the console debugging script at the end of the content.

What's the best way to avoid this?

1 Answer 1

8

Just remove these two logging routes from your plugin's init() method in your PluginHandlePlugin.php file:

craft()->log->removeRoute('WebLogRoute');
craft()->log->removeRoute('ProfileLogRoute');

That will prevent the extra logging and profiling information to be output in the browser's console when devMode is enabled.

2
  • Worked perfectly. Wouldn't you always want these removed when using methods like returnJson, or anything that explicitly returns non-html?
    – Tim Kelty
    Commented Jun 26, 2014 at 1:23
  • 1
    Entirely possible, I suppose.
    – Brad Bell
    Commented Jun 26, 2014 at 6:59

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.