Logging framework in moodle for development and debugging

Logging framework in moodle for development and debugging

by Alex Parsy -
Number of replies: 3
Hi All,
I looked through documentation and don't find anything that outlines standard way of doing logging for development/debug purposes.

I found out how to turn debugging on using the Admin console but I am interested to know if there is a good way to do fine grained and finely controlled debugging like the PEAR log package provides.

I've been using error_log(), as was mentioned in forum posting by some, but that I feel is not sufficient to for fine grained debugging at different log levels e.g..

Any suggestions ?


Average of ratings: -
In reply to Alex Parsy

Re: Logging framework in moodle for development and debugging

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Moodle does not used finely grained logging levels. I guess we have three:
  1. Debug off
  2. Debug ALL - outputs all errors.
  3. Debug DEVELOPER - outputs additional messages about mistakes developers may make.
Some of this controls standard PHP errors, other control the Moodle ways of raising errors like the debugging and print_error functions.

The there is a 4th level: when doing development, stick in extra calls to debugging or print_object to see what is going on in a particular piece of code - the take them out again before committing.

Oh, and there are extra add-hoc bits of logging, like the 'log email sending' option.
In reply to Tim Hunt

Re: Logging framework in moodle for development and debugging

by Alex Parsy -

Thanks Tim for the feedback and clarification on how things work.

I come from java and we have Log4j framework we use. I found PEAR logging framework to be closes to what I wanted.

I guess, there is nothing preventing me from incorporating PEAR logging into my modules. With it I can configured debug log statements e.g. "log.debug("....")" and then turn off these loggers by simply setting a parameters somewhere in a config file (possibly php.ini or config.php ) and I wouldn't have to worry about commenting out these statements when I deploy to production.

This I belive is equivalent to turnning debugging off using moodle Admin page.

But an extra benefit of using PEAR logging is that I can probably define Class specific or PHP file specific or even Module specific loggers and turn on/off that logger only.


K.

In reply to Alex Parsy

Re: Logging framework in moodle for development and debugging

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes, I read about Log4j and used it a bit, and it seems pretty cool. However, I don't feel any need for a highly engineered solution like that when working on Moodle. It is probably one of those things that differs between compiled and interpreted languages. It is just easier to go into the moodle code and add exactly the debugging statements you want at exactly the place you want them, rather than having to remember how to configure someone else's debug output.