162 lines
7.0 KiB
Plaintext
162 lines
7.0 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
function watchdog_help($section = "admin/help#watchdog") {
|
|
$output = "";
|
|
|
|
switch ($section) {
|
|
case 'admin/help#watchdog':
|
|
$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 %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, %log-entry. Needs \"cron.php\" to discard the entries.</p>";
|
|
$output = t($output, array("%watchdog" => l(t("check the watchdog report"), "admin/watchdog"), "%log-entry" => l(t("as configured"), "admin/system/modules/watchdog")));
|
|
break;
|
|
case 'admin/watchdog':
|
|
$output = 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.");
|
|
break;
|
|
case 'admin/watchdog/user':
|
|
$output = t("Watchdog events that have to do with users.");
|
|
break;
|
|
case 'admin/watchdog/regular':
|
|
$output = t("Watchdog events that are \"normal\" and have no other classification.");
|
|
break;
|
|
case 'admin/watchdog/httpd':
|
|
$output = t("Watchdog events that are from the web server.");
|
|
break;
|
|
case 'admin/watchdog/special':
|
|
$output = t("Watchdog events about adding, changing, and moderating nodes and comments.");
|
|
break;
|
|
case 'admin/watchdog/search':
|
|
$output = t("Watchdog events showing what users searched for.");
|
|
break;
|
|
case 'admin/watchdog/error':
|
|
$output = t("Watchdog events about PHP and database errors.");
|
|
break;
|
|
case 'admin/watchdog/warning':
|
|
$output = t("Watchdog warning events. These events don't stop Drupal from running, but are things you should know.");
|
|
break;
|
|
case 'admin/system/modules#description':
|
|
$output = t("Logs and records system events.");
|
|
break;
|
|
case 'admin/system/modules/watchdog':
|
|
$output = t("Watchdog logs your system events. To see these logs go to %watchdog. Since these logs can grow out of control if kept around forever, below set how long an item should be kept in the log. Note that to discard entries as set below you must run \"cron.php\" regularly.", array("%watchdog" => l(t("messages"), "admin/watchdog")));
|
|
break;
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
function watchdog_perm() {
|
|
return array("administer watchdog");
|
|
}
|
|
|
|
function watchdog_link($type) {
|
|
if ($type == "system") {
|
|
if (user_access("administer watchdog")) {
|
|
menu("admin/watchdog", t("messages"), "watchdog_admin", 6);
|
|
menu("admin/watchdog/view", t("view details"), "watchdog_admin", 0, MENU_HIDE);
|
|
|
|
foreach (_watchdog_get_message_types() as $type) {
|
|
menu("admin/watchdog/$type", t($type), "watchdog_admin");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function watchdog_settings() {
|
|
$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."));
|
|
return $output;
|
|
}
|
|
|
|
function watchdog_cron() {
|
|
db_query("DELETE FROM {watchdog} WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
|
|
}
|
|
|
|
function watchdog_overview($type) {
|
|
foreach (_watchdog_get_message_types() as $key) {
|
|
$query[$key] = "WHERE type = '". check_query($key) ."'";
|
|
}
|
|
$query['actions'] = "WHERE link != ''";
|
|
|
|
$header = array(
|
|
array("data" => t("date"), "field" => "w.timestamp", "sort" => "desc"),
|
|
array("data" => t("event"), "field" => "w.message"),
|
|
array("data" => t("user"), "field" => "u.name"),
|
|
array("data" => t("operations"), "colspan" => "2")
|
|
);
|
|
$sql = "SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : "");
|
|
$sql .= tablesort_sql($header);
|
|
$result = pager_query($sql, 50);
|
|
|
|
while ($watchdog = db_fetch_object($result)) {
|
|
$rows[] = array(
|
|
array("data" => format_date($watchdog->timestamp, "small"), "class" => "watchdog-$watchdog->type"),
|
|
array("data" => substr(strip_tags($watchdog->message), 0, 64), "class" => "watchdog-$watchdog->type"),
|
|
array("data" => format_name($watchdog), "class" => "watchdog-$watchdog->type"),
|
|
array("data" => $watchdog->link, "class" => "watchdog-$watchdog->type"),
|
|
array("data" => l(t("view details"), "admin/watchdog/view/$watchdog->wid"), "class" => "watchdog-$watchdog->type")
|
|
);
|
|
}
|
|
|
|
if (!$rows) {
|
|
$rows[] = array(array("data" => t("No log messages available."), "colspan" => "5"));
|
|
}
|
|
|
|
$pager = theme("pager", NULL, 50, 0, tablesort_pager());
|
|
if (!empty($pager)) {
|
|
$rows[] = array(array("data" => $pager, "colspan" => "5"));
|
|
}
|
|
return theme("table", $header, $rows);
|
|
}
|
|
|
|
function watchdog_view($id) {
|
|
|
|
$result = db_query("SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d", $id);
|
|
|
|
if ($watchdog = db_fetch_object($result)) {
|
|
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
|
|
$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>";
|
|
$output .= "</table>";
|
|
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
function watchdog_admin() {
|
|
|
|
if (user_access("administer watchdog")) {
|
|
switch (arg(2)) {
|
|
case "help":
|
|
$output = watchdog_help();
|
|
break;
|
|
case "view":
|
|
$output = watchdog_view(arg(3));
|
|
break;
|
|
default:
|
|
$output = watchdog_overview(arg(2));
|
|
}
|
|
print theme("page", $output);
|
|
}
|
|
else {
|
|
print theme("page", message_access());
|
|
}
|
|
}
|
|
|
|
function _watchdog_get_message_types() {
|
|
$types = array();
|
|
|
|
$result = db_query("SELECT DISTINCT(type) FROM {watchdog}");
|
|
while ($object = db_fetch_object($result)) {
|
|
$types[] = $object->type;
|
|
}
|
|
|
|
return $types;
|
|
}
|
|
|
|
?>
|