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
    Commented Aug 25, 2015 at 0:17
  • 2
    Is Tim's recently update answer on a separate question relevant here? civicrm.stackexchange.com/questions/3575/…
    – Laryn
    Commented May 6, 2016 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 :) Commented May 6, 2016 at 23:49

3 Answers 3


I use

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

to write to the log file.


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. Commented Aug 31, 2015 at 16:32

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 and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.