Debugging in Moodle

Debugging in Moodle

by Eric Richer -
Number of replies: 2

Hey folks,

In my experience, it's not uncommon for developers to use some kind of logging API to which they can send debugging statements to help in the supportability of their software.

To this extent, Moodle does have the function \debugging which appears to be useful for this purpose.

With that being said, I am noticing that when running unit tests, if any call to \debugging is made over the course of the execution of the test, the test will fail.

Am I mis-interpreting the purpose of \debugging?  Is it really only intended to be used to log errors?


Average of ratings: -
In reply to Eric Richer

Re: Debugging in Moodle

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Moodle's logging API is tied to events. When you trigger an event, it can be handled by multiple handlers, but it will always be captured and logged by the logging system.

As I understand it, debugging() is intended to output additional information when there is an error, not for silently logging. Unit tests capture debugging calls and can assert particular calls or the number of times it was called with assertDebuggingCalled() and assertDebuggingCalledCount(), so that you can test errors are being reported as desired.

You can also set up interactive debugging with XDebug.

In reply to Mark Johnson

Re: Debugging in Moodle

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I would not want to develop without Xdebug. The Free IDE VS Code integrates well with it.

Average of ratings: Useful (1)