来自 Moodle 插件的调试信息 [英] Debug Info from Moodle Plugin

查看:35
本文介绍了来自 Moodle 插件的调试信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Moodle 的新手.我正在尝试创建一个本地插件,它会在用户注册/取消注册时自动执行任务(发送电子邮件).

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.

在开发这个插件时,我正在尝试 echoprint_r 一些用于调试和跟踪目的的信息.

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

代码很简单

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

当我注释掉 echoprint_r 时,代码工作正常.对于 print_objectdebug 或任何其他打印函数,同样的问题仍然存在.

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.

推荐答案

在调试 Moodle 时,我通常使用 error_log 将消息正确打印到 Web 服务器的错误日志(/var/log/apache2/error.log 在带有 Apache 的类似 Debian 的发行版中).

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));

或者:

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

查看此问题以获取更多信息:如何将 var_dump 的结果捕获为字符串?

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

这篇关于来自 Moodle 插件的调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆