(Update) As of v4.7.0, the approaches below still work, but there's a better way to write to the log file using a PSR-3 logger, e.g.:
Civi::log()->info('Hello, log!');
Civi::log()->error('I'm sorry, {name}. I'm afraid I can't do that.', array(
'name' => 'Stanley Kubrick',
));
See also:
https://civicrm.org/blog/totten/the-static-is-dead-long-live-the-static
To write out to CiviCRM's ConfigAndLog
folder, one can use either:
CRM_Core_Error::debug_log_message('hello log');
CRM_Core_Error::debug_var('name', $var);
There's also an experimental PSR-3 logger (CRM_Utils_SystemLogger
) which writes out to the database (table civicrm_system_log
), e.g.
$log = new CRM_Utils_SystemLogger();
$log->info("hello log");
$log->error("I'm sorry, {name}. I'm afraid I can't do that.", array(
'name' => 'Stanley Kubrick',
));
If the debug statement is temporary (won't be committed/redistributed), then you can usually use CMS-specific functions (like Drupal devel's dpm()
or Joomla's JLog
).