Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.933 diff -u -r1.933 common.inc --- includes/common.inc 13 Jul 2009 21:09:53 -0000 1.933 +++ includes/common.inc 14 Jul 2009 00:17:52 -0000 @@ -4794,3 +4794,37 @@ } variable_set('css_js_query_string', $new_character . substr($string_history, 0, 19)); } + +function drupal_register_debug_function($function = NULL) { + $debug_function = &drupal_static(__FUNCTION__, '_drupal_debug'); + + if ($function) { + $debug_function = $function; + } + + return $debug_function; +} + +function dd($data, $label = NULL) { + drupal_debug($data, $label); +} + +function drupal_debug($data, $label = NULL) { + $function = drupal_register_debug_function(); + $function($data, $label); +} + +function _drupal_debug($data, $label = NULL) { + // Print $data contents to string. + $string = print_r($data, TRUE) . "\n"; + if ($label) { + $string = $label . ': ' . $string; + } + + // The temp directory does vary across multiple simpletest instances. + $file = file_directory_temp() . '/drupal_debug.log'; + if (file_put_contents($file, $string, FILE_APPEND) === FALSE) { + drupal_set_message(t('The temporary debug log cound not be written.'), 'error'); + return FALSE; + } +}