The 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 check the watchdog report on a regular basis as it is often the only way to tell what is going on.

', array('%watchdog' => url('admin/logs'))); case 'admin/logs': return t('The 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 check the watchdog report on a regular basis as it is often the only way to tell what is going on.'); case 'admin/logs/error': return t('Watchdog events about PHP and database errors.'); case 'admin/logs/httpd': return t('Watchdog events that are from the web server, like 404s, etc.'); case 'admin/logs/regular': return t('Watchdog events that are "normal" and have no other classification.'); case 'admin/logs/search': return t('Watchdog events showing what users have searched for.'); case 'admin/logs/special': return t('Watchdog events about adding, changing, and moderating nodes and comments.'); case 'admin/logs/user': return t('Watchdog events that have to do with users and their accounts.'); case 'admin/logs/warning': return t('Watchdog events that don\'t stop normal operation, but are things you should know.'); case 'admin/modules#description': return t('Logs and records system events.'); } } /** * Implementation of hook_menu(). */ function watchdog_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/logs', 'title' => t('logs'), 'callback' => 'watchdog_overview', 'access' => user_access('administer watchdog')); $items[] = array('path' => 'admin/logs/view', 'title' => t('view details'), 'callback' => 'watchdog_view', 'access' => user_access('administer watchdog'), 'type' => MENU_CALLBACK); foreach (_watchdog_get_message_types() as $type) { $items[] = array('path' => 'admin/logs/'. $type, 'title' => t($type), 'type' => MENU_DYNAMIC_ITEM); } } return $items; } /** * Implementation of hook_perm(). */ function watchdog_perm() { return array('administer watchdog'); } /** * Implementation of hook_cron(). * * Remove expired log messages. */ function watchdog_cron() { db_query('DELETE FROM {watchdog} WHERE '. time() .' - timestamp > '. variable_get('watchdog_clear', 604800)); } /** * Menu callback; displays a listing of log messages. */ function watchdog_overview($type = '') { foreach (_watchdog_get_message_types() as $key) { $query[$key] = "WHERE type = '". check_query($key) ."'"; } $header = array( array('data' => t('Date'), 'field' => 'w.timestamp', 'sort' => 'desc'), array('data' => t('Message'), '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] : '') . tablesort_sql($header); $result = pager_query($sql, 50); while ($watchdog = db_fetch_object($result)) { $rows[] = array('data' => array( // Cells format_date($watchdog->timestamp, 'small'), truncate_utf8(strip_tags($watchdog->message), 64), format_name($watchdog), $watchdog->link, l(t('details'), "admin/logs/view/$watchdog->wid") ), // Attributes for tr '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')); } print theme('page', theme('table', $header, $rows)); } /** * Menu callback; displays details about a log message. */ function watchdog_view($id) { $output = ''; $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 .= ''; $output .= ' "; $output .= ' '; $output .= ' '; $output .= ' "; $output .= ' "; $output .= ' "; $output .= '
'. t('Type') ."$watchdog->type
'. t('Date') .''. format_date($watchdog->timestamp, 'large') .'
'. t('User') .''. format_name($watchdog) .'
'. t('Location') ."$watchdog->location
'. t('Message') ."$watchdog->message
'. t('Hostname') ."$watchdog->hostname
'; } print theme('page', $output); } 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; } ?>