You are here

function error_log_watchdog in Error Log 7

Implements hook_watchdog().

File

./error_log.module, line 31
Sends watchdog log entries to the PHP error log.

Code

function error_log_watchdog(array $log) {
  $levels = variable_get('error_log_levels', error_log_default_levels());
  if (empty($levels["level_{$log['severity']}"])) {
    return;
  }

  // Drush handles error logging for us, so disable redundant logging.
  if (function_exists('drush_main') && !ini_get('error_log')) {
    return;
  }
  $ignored_types = array_map('trim', preg_split('/\\R/', variable_get('error_log_ignored_types', ''), -1, PREG_SPLIT_NO_EMPTY));
  if (in_array($log['type'], $ignored_types)) {
    return;
  }
  if (!is_array($log['variables'])) {
    $log['variables'] = array();
  }
  $severity_list = error_log_severity_levels();
  $message = "[{$severity_list[$log['severity']]}] [{$log['type']}] [{$log['ip']}] [uid:{$log['uid']}] [{$log['request_uri']}] [{$log['referer']}] ";

  // Cleanup excessive whitespace and HTML-encoded quotes.
  $message .= str_replace(array(
    '    ',
    "\n",
  ), '', html_entity_decode(strip_tags(strtr($log['message'], $log['variables'])), ENT_QUOTES, 'UTF-8'));
  return error_log($message);
}