Debug Info from Moodle Plugin

最后都变了- 提交于 2019-12-11 03:55:40

问题


I am a newbie to Moodle. I am trying to create a local plug which would do tasks (sending email) automatically when user is enrolled / unenrolled.

While developing this plugin, I am trying to echo or print_r some information for debug and tracing purposes.

The code is as simple as

function perform_enrol($eventdata){
        echo 'Hello World';
        print_r($eventdata);
        return true;
}

However, when the code executes, I get the following error occurs:

> Syntax Error File:
> http://192.168.10.60/moodle/theme/yui_combo.php?3.9.1/build/simpleyui/simpleyui.js&3.9.1/build/loader/loader.js
> Line: 18541

When I comment out the echo and print_r , the code works fine. The same problem continues for print_object , debug or any other printing functions.

Is there a specific way to print from plugins. I have used these functions in core code in past and seems to work fine.


回答1:


When I'm debugging Moodle, I usually use error_log to print the message right to the error log of the web server (/var/log/apache2/error.log in a Debian-like distribution with Apache).

So, to inspect some variable, I need to use a function that return it as a string. Something like this:

error_log('My variable x is: ' . print_r($variable, true));

Or:

error_log('My variable x is: ' . var_export($variable, true));

Take a look at this question for more information: How can I capture the result of var_dump to a string?




回答2:


This is not the issue with the debug message from the plugin. This is due to outputting a message before an Ajax request. Please check if there are any ajax request in the particular plugin or in Moodle default pages. There is no specific debug messages specific for plugins. You can use any php built in debug functions.

Hope this helps.



来源:https://stackoverflow.com/questions/18224372/debug-info-from-moodle-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!