Skip to content
watchdog.module 6.85 KiB
Newer Older
Dries Buytaert's avatar
 
Dries Buytaert committed
<?php
Dries Buytaert's avatar
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
function watchdog_help() {
Dries Buytaert's avatar
 
Dries Buytaert committed

  $output .= "<p>Watchdog module monitors your web site, capturing system events in a log to be reviewed by an authorized individual at a later time.  The Watchdog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information.  It is vital to ". l("check the Watchdog report", "admin/watchdog") ." on a regular basis as it is often the only way to tell what is going on.</p>";
  $output .= "<p>To ease administration, the watchdog will automatically discard old log entries, ". l("as configured", "admin/system/modules/watchdog") .". Needs \"cron.php\" to discard the entries.</p>";
  return t($output);
Dries Buytaert's avatar
 
Dries Buytaert committed
}

function watchdog_system($field){
  $system["description"] = t("Logs and records system events.");
Dries Buytaert's avatar
 
Dries Buytaert committed
  $system["admin_help"] = t("Watchdog logs your system events. To see these logs go to <a href=\"%watchdog\">Site monitoring</a>. Since these logs can grow out of control if kept around forever, below set how long an item should be kept in the log.<br />Note:<ul><li>To discard entries as set below you must run \"cron.php\" regularly.</li></ul>", array("%watchdog" => url("admin/watchdog")));
Dries Buytaert's avatar
 
Dries Buytaert committed
function watchdog_perm() {
Dries Buytaert's avatar
 
Dries Buytaert committed
  return array("administer watchdog");
Dries Buytaert's avatar
 
Dries Buytaert committed
}

Dries Buytaert's avatar
 
Dries Buytaert committed
function watchdog_link($type) {
Dries Buytaert's avatar
 
Dries Buytaert committed
  if ($type == "admin" && user_access("administer watchdog")) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    $help["general"] = t("The watchdog module monitors your web site, captures system events in a log and records them to be reviewed by an authorized individual at a later time.  The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information. It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.");
    $help["user"] = t("Watchdog events that have to do with users. Most of these come from the user.module.");
    $help["regular"] = t("Watchdog events that are \"normal\" and have no other classification.");
    $help["httpd"] = t("Watchdog events that are from the web server.<br />Note: At this time this logging level is <b>not</b> used.");
    $help["special"] = t("Watchdog events about adding, changing, and moderating nodes and comments.");
    $help["error"] = t("Watchdog general error events, such as invalid login, permission denied, and database errors.");
    $help["warning"] = t("Watchdog warning events. These events don't stop Drupal from running, but are things you should no to correct.");
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
    menu("admin/watchdog", "site monitoring", "watchdog_admin", $help["general"], 6);
    menu("admin/watchdog/user", "user messages", "watchdog_admin", $help["user"]);
    menu("admin/watchdog/regular", "regular messages", "watchdog_admin", $help["regular"]);
    menu("admin/watchdog/special", "special messages", "watchdog_admin", $help["special"]);
    menu("admin/watchdog/warning", "warning messages", "watchdog_admin", $help["warning"]);
    menu("admin/watchdog/error", "error messages", "watchdog_admin", $help["error"]);
    menu("admin/watchdog/httpd", "httpd messages", "watchdog_admin", $help["http"]);
    menu("admin/watchdog/view", "view details", "watchdog_admin", $help["general"], 0, 1); // hidden menu
Dries Buytaert's avatar
 
Dries Buytaert committed
  }
}

Dries Buytaert's avatar
 
Dries Buytaert committed
  $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200), 1000000000 => t("Never"));
  $output .= form_select(t("Discard entries older than"), "watchdog_clear", variable_get("watchdog_clear", 604800), $period, t("The time watchdog entries should be kept.  Older entries will be automatically discarded.  Requires crontab."));
Dries Buytaert's avatar
 
Dries Buytaert committed
  return $output;
}

Dries Buytaert's avatar
 
Dries Buytaert committed
function watchdog_cron() {
Dries Buytaert's avatar
 
Dries Buytaert committed
  db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
Dries Buytaert's avatar
 
Dries Buytaert committed
}
Dries Buytaert's avatar
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
function watchdog_overview($type) {
Dries Buytaert's avatar
 
Dries Buytaert committed
  $color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C");
  $query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''");
Dries Buytaert's avatar
Dries Buytaert committed

Dries Buytaert's avatar
Dries Buytaert committed
  $result = pager_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 50);
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
Dries Buytaert committed
  while ($watchdog = db_fetch_object($result)) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    if ($background = $color[$watchdog->type]) {
Dries Buytaert's avatar
 
Dries Buytaert committed
      $data .= " <tr style=\"background-color: $background\"><td>". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($watchdog->message), 0, 64) ."</td><td style=\"text-align: center;\">". format_name($watchdog) ."</td><td style=\"text-align: center;\">$watchdog->link</td><td style=\"text-align: center;\">". l(t("view details"), "admin/watchdog/view/$watchdog->wid") ."</td></tr>";
Dries Buytaert's avatar
 
Dries Buytaert committed
    }
Dries Buytaert's avatar
Dries Buytaert committed
  }
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
  $output .= "<table>";
  $output .= " <tr><th>" . t("date") . "</th><th>" . t("event") . "</th><th>" . t("user") . "</th><th colspan=\"2\">" . t("operations") . "</th></tr>";
Dries Buytaert's avatar
 
Dries Buytaert committed
  $output .= ($data ? $data : "<tr><td style=\"text-align: center;\" colspan=\"4\">". t("No system messages currently available.") ."</td></tr>");
  $output .= (($pager = pager_display(NULL, 50, 0, "admin")) ? "<tr><td style=\"text-align: center;\" colspan=\"4\">$pager</td></tr>" : "");
Dries Buytaert's avatar
 
Dries Buytaert committed
  $output .= "</table>";
Dries Buytaert's avatar
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
  return $output;
Dries Buytaert's avatar
Dries Buytaert committed
}

function watchdog_view($id) {
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
  $result = db_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid WHERE w.wid = %d", $id);
Dries Buytaert's avatar
Dries Buytaert committed

  if ($watchdog = db_fetch_object($result)) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
Dries Buytaert's avatar
 
Dries Buytaert committed
    $output .= " <tr><th>". t("Type") ."</th><td>$watchdog->type</td></tr>";
    $output .= " <tr><th>". t("Date") ."</th><td>". format_date($watchdog->timestamp, "large") ."</td></tr>";
    $output .= " <tr><th>". t("User") ."</th><td>". format_name($watchdog) ."</td></tr>";
    $output .= " <tr><th>". t("Location") ."</th><td>$watchdog->location</td></tr>";
    $output .= " <tr><th>". t("Message") ."</th><td>$watchdog->message</td></tr>";
    $output .= " <tr><th>". t("Hostname") ."</th><td>$watchdog->hostname</td></tr>";
Dries Buytaert's avatar
 
Dries Buytaert committed
    $output .= "</table>";
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
    return $output;
  }
Dries Buytaert's avatar
 
Dries Buytaert committed
}

Dries Buytaert's avatar
Dries Buytaert committed
function watchdog_admin() {
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
  if (user_access("administer watchdog")) {
Dries Buytaert's avatar
 
Dries Buytaert committed
    switch (arg(2)) {
Dries Buytaert's avatar
 
Dries Buytaert committed
      case "help":
        watchdog_help();
        break;
      case "view":
Dries Buytaert's avatar
 
Dries Buytaert committed
        print watchdog_view(arg(3));
Dries Buytaert's avatar
 
Dries Buytaert committed
        break;
      default:
Dries Buytaert's avatar
 
Dries Buytaert committed
        print watchdog_overview(arg(2));
Dries Buytaert's avatar
 
Dries Buytaert committed
    }
  }
  else {
    print message_access();
Dries Buytaert's avatar
Dries Buytaert committed
  }
}
Dries Buytaert's avatar
 
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
?>