Answers.Body: <p>I use </p>
  
  <pre><code>Civi::log()-&gt;debug('my message') 
  </code></pre>
  
  <p>to write to the log file.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-18T19:56:29.717Z
Answers.LastActivityDate: 2019-09-18T19:56:29.717Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>There are two good questions here:</p>
  
  <ol>
  <li>How to write debug info out while trying to debug something specific.</li>
  <li>What kind of debug info to write out when writing an extension to help others who will be debugging stuff in your code later.</li>
  </ol>
  
  <p>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.</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-31T16:32:16.670Z
Answers.Text: 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.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-31T15:06:06.670Z
Answers.LastActivityDate: 2015-08-31T15:06:06.670Z
Answers.UserDisplayName: Alan Dixon
Answers.Body: <p>Had the same question in 2019 and from reading the source the answer is now <code>CRM_Core_Error::</code><a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Error.php#L578" rel="nofollow noreferrer">debug_log_message()</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-18T18:32:25.400Z
Answers.LastActivityDate: 2019-09-18T18:32:25.400Z
Answers.UserDisplayName: lynxlynxlynx
Body: <p>The "current" wiki says to use <code>CRM_Core_Error::debug</code> 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 <code>$log = true</code>, <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Error.php#L508">that just does an echo</a>.</p>
  
  <p>An <a href="http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=33129619">older version</a> of the docs says to use <code>debug_var</code> - and this works correctly, but seems duplicative, and isn't mentioned in the current docs.</p>
  
  <p>Should the documentation be changed?  Or should the code be refactored?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-25T00:17:22.087Z
Comments.Text: 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.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-06T18:18:57.260Z
Comments.Text: Is Tim's recently update answer on a separate question relevant here? http://civicrm.stackexchange.com/questions/3575/how-to-print-variable-debug-data-from-your-extension-php/3576#3576
Comments.UserDisplayName: Laryn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-06T23:49:35.530Z
Comments.Text: @Laryn-CEDC.org - yes, definitely!  I saw this earlier today; I'm glad it's documented here, even if not on the wiki :)
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <developer><debugging>
Title: What's the correct way to log debug info to log?
ThreadText: # What's the correct way to log debug info to log?
  
  (Asked by: username_0 on 2015-08-21)
  
  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](https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Error.php#L508).
  
  An [older version](http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=33129619) 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?
  
  **Tags:** developer, debugging
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_2**: Is Tim's recently update answer on a separate question relevant here? http://civicrm.stackexchange.com/questions/3575/how-to-print-variable-debug-data-from-your-extension-php/3576#3576  
  > **username_0**: @username_2-CEDC.org - yes, definitely!  I saw this earlier today; I'm glad it's documented here, even if not on the wiki :)  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2019-09-18. Score: 2
  
  I use 
  Civi::log()->debug('my message') 
  
  to write to the log file.
  
  
  ---
  
  ### Answer by username_4 on 2015-08-31. Score: 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.
  
  > **Comments:**
  > **username_0**: 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.  
  
  ---
  
  ### Answer by username_5 on 2019-09-18. Score: 1
  
  Had the same question in 2019 and from reading the source the answer is now `CRM_Core_Error::`[debug\_log\_message()](https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Error.php#L578).
  
  
  ---
  
  