- Patch #79622 by Dries: added views to see the most popular search terms,

the most important 404s and 403s.  This makes the watchdog data easier to
  use.  Improved consistency of the 'amdminister > logs' section.
5.x
Dries Buytaert 2006-08-29 09:51:50 +00:00
parent bceaf8f0da
commit 78ee75f1a2
4 changed files with 53 additions and 14 deletions

View File

@ -318,7 +318,8 @@ function drupal_site_offline() {
*/ */
function drupal_not_found() { function drupal_not_found() {
drupal_set_header('HTTP/1.0 404 Not Found'); drupal_set_header('HTTP/1.0 404 Not Found');
watchdog('page not found', t('%page not found.', array('%page' => $_GET['q'])), WATCHDOG_WARNING);
watchdog('page not found', check_plain($_GET['q']), WATCHDOG_WARNING);
// Keep old path for reference // Keep old path for reference
if (!isset($_REQUEST['destination'])) { if (!isset($_REQUEST['destination'])) {
@ -347,7 +348,7 @@ function drupal_not_found() {
*/ */
function drupal_access_denied() { function drupal_access_denied() {
drupal_set_header('HTTP/1.0 403 Forbidden'); drupal_set_header('HTTP/1.0 403 Forbidden');
watchdog('access denied', t('%page denied access.', array('%page' => $_GET['q'])), WATCHDOG_WARNING, l(t('view'), $_GET['q'])); watchdog('access denied', check_plain($_GET['q']), WATCHDOG_WARNING);
// Keep old path for reference // Keep old path for reference
if (!isset($_REQUEST['destination'])) { if (!isset($_REQUEST['destination'])) {

View File

@ -170,6 +170,10 @@ function search_menu($may_cache) {
'callback arguments' => array('search_wipe_confirm'), 'callback arguments' => array('search_wipe_confirm'),
'access' => user_access('administer search'), 'access' => user_access('administer search'),
'type' => MENU_CALLBACK); 'type' => MENU_CALLBACK);
$items[] = array('path' => 'admin/logs/search', 'title' => t('top search phrases'),
'description' => t('View most popular search phrases.'),
'callback' => 'watchdog_top',
'callback arguments' => array('search'));
} }
else if (arg(0) == 'search') { else if (arg(0) == 'search') {
// To remember the user's search keywords when switching across tabs, // To remember the user's search keywords when switching across tabs,
@ -920,7 +924,7 @@ function search_view() {
// Only perform search if there is non-whitespace search term: // Only perform search if there is non-whitespace search term:
if (trim($keys)) { if (trim($keys)) {
// Log the search keys: // Log the search keys:
watchdog('search', t('Search: %keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name'))), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys)); watchdog('search', t('%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name'))), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
// Collect the search results: // Collect the search results:
$results = search_data($keys, $type); $results = search_data($keys, $type);

View File

@ -117,10 +117,9 @@ function statistics_menu($may_cache) {
$items[] = array( $items[] = array(
'path' => 'admin/logs/hits', 'path' => 'admin/logs/hits',
'title' => t('recent hits'), 'title' => t('recent hits'),
'description' => t('View pages that have recently been hit.'), 'description' => t('View pages that have recently been visited.'),
'callback' => 'statistics_recent_hits', 'callback' => 'statistics_recent_hits',
'access' => $access, 'access' => $access);
'weight' => 3);
$items[] = array( $items[] = array(
'path' => 'admin/logs/pages', 'path' => 'admin/logs/pages',
'title' => t('top pages'), 'title' => t('top pages'),
@ -137,7 +136,7 @@ function statistics_menu($may_cache) {
'weight' => 2); 'weight' => 2);
$items[] = array( $items[] = array(
'path' => 'admin/logs/referrers', 'path' => 'admin/logs/referrers',
'title' => t('referrers'), 'title' => t('top referrers'),
'description' => t('View top referrers.'), 'description' => t('View top referrers.'),
'callback' => 'statistics_top_referrers', 'callback' => 'statistics_top_referrers',
'access' => $access); 'access' => $access);
@ -155,8 +154,8 @@ function statistics_menu($may_cache) {
'callback' => 'drupal_get_form', 'callback' => 'drupal_get_form',
'callback arguments' => array('statistics_access_logging_settings'), 'callback arguments' => array('statistics_access_logging_settings'),
'access' => user_access('administer site configuration'), 'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM 'type' => MENU_NORMAL_ITEM,
); 'weight' => 3);
} }
else { else {
if (arg(0) == 'user' && is_numeric(arg(1)) && variable_get('statistics_enable_access_log', 0)) { if (arg(0) == 'user' && is_numeric(arg(1)) && variable_get('statistics_enable_access_log', 0)) {

View File

@ -47,10 +47,18 @@ function watchdog_menu($may_cache) {
'callback' => 'system_admin_menu_block_page', 'callback' => 'system_admin_menu_block_page',
'weight' => 5, 'weight' => 5,
'position' => 'left'); 'position' => 'left');
$items[] = array('path' => 'admin/logs/watchdog', 'title' => t('watchdog log'), $items[] = array('path' => 'admin/logs/watchdog', 'title' => t('recent log entries'),
'description' => t('View the primary system log.'), 'description' => t('View events that have recently been logged.'),
'weight' => -10, 'callback' => 'watchdog_overview',
'callback' => 'watchdog_overview'); 'weight' => -1);
$items[] = array('path' => 'admin/logs/page-not-found', 'title' => t("top 'page not found' errors"),
'description' => t("View 'page not found errors' (404s)."),
'callback' => 'watchdog_top',
'callback arguments' => array('page not found'));
$items[] = array('path' => 'admin/logs/access-denied', 'title' => t("top 'access denied' errors"),
'description' => t("View 'access denied' errors (403s)."),
'callback' => 'watchdog_top',
'callback arguments' => array('access denied'));
$items[] = array('path' => 'admin/logs/event', 'title' => t('details'), $items[] = array('path' => 'admin/logs/event', 'title' => t('details'),
'callback' => 'watchdog_event', 'callback' => 'watchdog_event',
'type' => MENU_CALLBACK); 'type' => MENU_CALLBACK);
@ -160,6 +168,33 @@ function watchdog_overview() {
return $output; return $output;
} }
/**
* Menu callback; generic function to display a page of the most frequent
* watchdog events of a specified type.
*/
function watchdog_top($type) {
$header = array(
array('data' => t('Count'), 'field' => 'count', 'sort' => 'desc'),
array('data' => t('Message'), 'field' => 'message')
);
$result = pager_query("SELECT COUNT(wid) AS count, message FROM {watchdog} WHERE type = '%s' GROUP BY message ". tablesort_sql($header), 30, 0, "SELECT COUNT(DISTINCT(message)) FROM {watchdog} WHERE type = '%s'", $type);
while ($watchdog = db_fetch_object($result)) {
$rows[] = array($watchdog->count, truncate_utf8($watchdog->message, 56, TRUE, TRUE));
}
if (!$rows) {
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => 2));
}
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}
function theme_watchdog_form_overview($form) { function theme_watchdog_form_overview($form) {
return '<div class="container-inline">'. drupal_render($form) .'</div>'; return '<div class="container-inline">'. drupal_render($form) .'</div>';
} }