Commit 78ee75f1 authored by Dries's avatar Dries

- 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.
parent bceaf8f0
......@@ -318,7 +318,8 @@ function drupal_site_offline() {
*/
function drupal_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
if (!isset($_REQUEST['destination'])) {
......@@ -347,9 +348,9 @@ function drupal_not_found() {
*/
function drupal_access_denied() {
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'])) {
$_REQUEST['destination'] = $_GET['q'];
}
......
......@@ -170,6 +170,10 @@ function search_menu($may_cache) {
'callback arguments' => array('search_wipe_confirm'),
'access' => user_access('administer search'),
'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') {
// 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:
if (trim($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:
$results = search_data($keys, $type);
......
......@@ -117,10 +117,9 @@ function statistics_menu($may_cache) {
$items[] = array(
'path' => 'admin/logs/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',
'access' => $access,
'weight' => 3);
'access' => $access);
$items[] = array(
'path' => 'admin/logs/pages',
'title' => t('top pages'),
......@@ -137,7 +136,7 @@ function statistics_menu($may_cache) {
'weight' => 2);
$items[] = array(
'path' => 'admin/logs/referrers',
'title' => t('referrers'),
'title' => t('top referrers'),
'description' => t('View top referrers.'),
'callback' => 'statistics_top_referrers',
'access' => $access);
......@@ -155,8 +154,8 @@ function statistics_menu($may_cache) {
'callback' => 'drupal_get_form',
'callback arguments' => array('statistics_access_logging_settings'),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM
);
'type' => MENU_NORMAL_ITEM,
'weight' => 3);
}
else {
if (arg(0) == 'user' && is_numeric(arg(1)) && variable_get('statistics_enable_access_log', 0)) {
......
......@@ -47,10 +47,18 @@ function watchdog_menu($may_cache) {
'callback' => 'system_admin_menu_block_page',
'weight' => 5,
'position' => 'left');
$items[] = array('path' => 'admin/logs/watchdog', 'title' => t('watchdog log'),
'description' => t('View the primary system log.'),
'weight' => -10,
'callback' => 'watchdog_overview');
$items[] = array('path' => 'admin/logs/watchdog', 'title' => t('recent log entries'),
'description' => t('View events that have recently been logged.'),
'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'),
'callback' => 'watchdog_event',
'type' => MENU_CALLBACK);
......@@ -160,6 +168,33 @@ function watchdog_overview() {
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) {
return '<div class="container-inline">'. drupal_render($form) .'</div>';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment