6

The "current" wiki says to use CRM_Core_Error::debug and says, "Most runtime errors are logged here, as well as data that you explicitly write to log using the CRM_Core_Error::debug log=true parameter." However, if you set $log = true, that just does an echo.

An older version of the docs says to use debug_var - and this works correctly, but seems duplicative, and isn't mentioned in the current docs.

Should the documentation be changed? Or should the code be refactored?

  • For one-offs I usually use CRM_Core_Error::debug_log_message(print_r($thing_to_debug, true)); since I do remember having problems with debug_var() a long time ago. The wiki seems to be an oversight or something lost in rewrites, since as you note the code is still there. But for bigger stuff if it's a local development copy I really do recommend the netbeans + xdebug setup the current wiki describes at the bottom, and it or other debuggers have a variables pane where you can examine the variable in realtime. – Demerit Aug 25 '15 at 0:17
  • 2
    Is Tim's recently update answer on a separate question relevant here? civicrm.stackexchange.com/questions/3575/… – Laryn - CEDC.org May 6 '16 at 18:18
  • 1
    @Laryn-CEDC.org - yes, definitely! I saw this earlier today; I'm glad it's documented here, even if not on the wiki :) – Jon G - Megaphone Tech May 6 '16 at 23:49
1

There are two good questions here:

  1. How to write debug info out while trying to debug something specific.
  2. What kind of debug info to write out when writing an extension to help others who will be debugging stuff in your code later.

The first one is probably best handled with the debugging facilities you're used to, from whatever CMS you're using. I like Drupal's dpm() function in the devel module for easy industrial strength debugging.

The second one is probably what you're asking, and I'm glad you did because I don't know the right answer either. My own code is selfishly just checking the civicrm settings for user framework logging and debug settings and using drupal watchdog when it sees them on.

  • I'm actually asking the first question, but it's less that I'm asking for myself - I know how to get what I want - and more because the docs appear to be incorrect and I want to fix them. I'm not sure whether to make the code match the docs or vice versa. – Jon G - Megaphone Tech Aug 31 '15 at 16:32
1

I use

Civi::log()->debug('my message') 

to write to the log file.

0

Had the same question in 2019 and from reading the source the answer is now CRM_Core_Error::debug_log_message().

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.