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?

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
    Jun 26 '14 at 1:23
  • 1
    Entirely possible, I suppose.
    – Brad Bell
    Jun 26 '14 at 6:59

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.