View source
<?php
define('WATCHDOG_FILTERING_EXCLUDE', 'exclude');
define('WATCHDOG_FILTERING_INCLUDE', 'include');
define('WATCHDOG_FILTERING_IGNORE', 'ignore');
function watchdog_filtering_menu() {
$items = array();
$items['admin/config/development/logging/general'] = array(
'title' => 'Logging and errors',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/development/logging/filtering'] = array(
'title' => 'Filtering',
'description' => 'Watchdog Filtering settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'watchdog_filtering_settings_form',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_LOCAL_TASK,
'file' => 'watchdog_filtering.admin.inc',
);
return $items;
}
function watchdog_filtering_module_implements_alter(&$implementations, $hook) {
if ($hook == 'watchdog') {
foreach ($implementations as $module => $group) {
if ($group) {
module_load_include('inc', $module, "{$module}.{$group}");
}
if (!function_exists($module . '_' . $hook)) {
unset($implementations[$module]);
}
}
unset($implementations['watchdog_filtering']);
$implementations['system'] = FALSE;
if (variable_get('watchdog_filtering_implementations', array()) != $implementations) {
$GLOBALS['conf']['watchdog_filtering_implementations'] = $implementations;
drupal_register_shutdown_function('variable_set', 'watchdog_filtering_implementations', $implementations);
}
$implementations = array(
'watchdog_filtering' => FALSE,
);
}
}
function _watchdog_filtering_get_levels() {
global $conf;
$levels = array();
foreach ($conf as $key => $value) {
if (preg_match('/^watchdog_filtering_severity_(.*)$/', $key, $matches)) {
$levels[$matches[1]] = $value;
}
}
return $levels;
}
function watchdog_filtering_invoke_filtering($log_entry) {
$unique =& drupal_static('watchdog_filtering_unique', array());
if (variable_get('watchdog_filtering_deduplicate', FALSE)) {
$key = md5(serialize($log_entry));
if (isset($unique[$key])) {
return WATCHDOG_FILTERING_EXCLUDE;
}
$unique[$key] = TRUE;
}
$type = rawurlencode($log_entry['type']);
$severity = variable_get('watchdog_filtering_severity_' . $type, NULL);
if (!isset($severity)) {
$severity = FALSE;
variable_set('watchdog_filtering_severity_' . $type, $severity);
}
if ($severity === FALSE) {
$severity = variable_get('watchdog_filtering_default_severity', array_keys(watchdog_severity_levels()));
}
$status = module_invoke_all('watchdog_filtering', $log_entry);
if (in_array(WATCHDOG_FILTERING_EXCLUDE, $status, TRUE)) {
return WATCHDOG_FILTERING_EXCLUDE;
}
elseif (in_array(WATCHDOG_FILTERING_INCLUDE, $status, TRUE)) {
return WATCHDOG_FILTERING_INCLUDE;
}
if (in_array($log_entry['severity'], $severity)) {
return WATCHDOG_FILTERING_INCLUDE;
}
else {
return WATCHDOG_FILTERING_EXCLUDE;
}
}
function watchdog_filtering_watchdog(array $log_entry) {
if (watchdog_filtering_invoke_filtering($log_entry) === WATCHDOG_FILTERING_EXCLUDE) {
return;
}
$implementations = variable_get('watchdog_filtering_implementations', array());
$return = array();
foreach ($implementations as $module => $group) {
$function = $module . '_watchdog';
if (function_exists($function)) {
call_user_func($function, $log_entry);
}
else {
unset($GLOBALS['conf']['watchdog_filtering_implementations'][$module]);
}
}
return $return;
}