Mercurial > defr > drupal > core
comparison modules/dblog/dblog.module @ 1:c1f4ac30525a 6.0
Drupal 6.0
| author | Franck Deroche <webmaster@defr.org> |
|---|---|
| date | Tue, 23 Dec 2008 14:28:28 +0100 |
| parents | |
| children | 2427550111ae |
comparison
equal
deleted
inserted
replaced
| 0:5a113a1c4740 | 1:c1f4ac30525a |
|---|---|
| 1 <?php | |
| 2 // $Id: dblog.module,v 1.21 2008/01/08 10:35:41 goba Exp $ | |
| 3 | |
| 4 /** | |
| 5 * @file | |
| 6 * System monitoring and logging for administrators. | |
| 7 * | |
| 8 * The dblog module monitors your site and keeps a list of | |
| 9 * recorded events containing usage and performance data, errors, | |
| 10 * warnings, and similar operational information. | |
| 11 * | |
| 12 * @see watchdog() | |
| 13 */ | |
| 14 | |
| 15 /** | |
| 16 * Implementation of hook_help(). | |
| 17 */ | |
| 18 function dblog_help($path, $arg) { | |
| 19 switch ($path) { | |
| 20 case 'admin/help#dblog': | |
| 21 $output = '<p>'. t('The dblog module monitors your system, capturing system events in a log to be reviewed by an authorized individual at a later time. This is useful for site administrators who want a quick overview of activities on their site. The logs also record the sequence of events, so it can be useful for debugging site errors.') .'</p>'; | |
| 22 $output .= '<p>'. t('The dblog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information. Administrators should check the dblog report on a regular basis to ensure their site is working properly.') .'</p>'; | |
| 23 $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@dblog">Dblog module</a>.', array('@dblog' => 'http://drupal.org/handbook/modules/dblog/')) .'</p>'; | |
| 24 return $output; | |
| 25 case 'admin/reports/dblog': | |
| 26 return '<p>'. t('The dblog module monitors your website, capturing system events in a log to be reviewed by an authorized individual at a later time. The dblog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information. It is vital to check the dblog report on a regular basis as it is often the only way to tell what is going on.') .'</p>'; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 /** | |
| 31 * Implementation of hook_theme() | |
| 32 */ | |
| 33 function dblog_theme() { | |
| 34 return array( | |
| 35 'dblog_filters' => array( | |
| 36 'arguments' => array('form' => NULL), | |
| 37 ), | |
| 38 ); | |
| 39 } | |
| 40 | |
| 41 /** | |
| 42 * Implementation of hook_menu(). | |
| 43 */ | |
| 44 function dblog_menu() { | |
| 45 $items['admin/settings/logging/dblog'] = array( | |
| 46 'title' => 'Database logging', | |
| 47 'description' => 'Settings for logging to the Drupal database logs. This is the most common method for small to medium sites on shared hosting. The logs are viewable from the admin pages.', | |
| 48 'page callback' => 'drupal_get_form', | |
| 49 'page arguments' => array('dblog_admin_settings'), | |
| 50 'file' => 'dblog.admin.inc', | |
| 51 ); | |
| 52 | |
| 53 $items['admin/reports/dblog'] = array( | |
| 54 'title' => 'Recent log entries', | |
| 55 'description' => 'View events that have recently been logged.', | |
| 56 'page callback' => 'dblog_overview', | |
| 57 'weight' => -1, | |
| 58 'file' => 'dblog.admin.inc', | |
| 59 ); | |
| 60 $items['admin/reports/page-not-found'] = array( | |
| 61 'title' => "Top 'page not found' errors", | |
| 62 'description' => "View 'page not found' errors (404s).", | |
| 63 'page callback' => 'dblog_top', | |
| 64 'page arguments' => array('page not found'), | |
| 65 'file' => 'dblog.admin.inc', | |
| 66 ); | |
| 67 $items['admin/reports/access-denied'] = array( | |
| 68 'title' => "Top 'access denied' errors", | |
| 69 'description' => "View 'access denied' errors (403s).", | |
| 70 'page callback' => 'dblog_top', | |
| 71 'page arguments' => array('access denied'), | |
| 72 'file' => 'dblog.admin.inc', | |
| 73 ); | |
| 74 $items['admin/reports/event/%'] = array( | |
| 75 'title' => 'Details', | |
| 76 'page callback' => 'dblog_event', | |
| 77 'page arguments' => array(3), | |
| 78 'type' => MENU_CALLBACK, | |
| 79 'file' => 'dblog.admin.inc', | |
| 80 ); | |
| 81 return $items; | |
| 82 } | |
| 83 | |
| 84 function dblog_init() { | |
| 85 if (arg(0) == 'admin' && arg(1) == 'reports') { | |
| 86 // Add the CSS for this module | |
| 87 drupal_add_css(drupal_get_path('module', 'dblog') .'/dblog.css', 'module', 'all', FALSE); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 | |
| 92 | |
| 93 /** | |
| 94 * Implementation of hook_cron(). | |
| 95 * | |
| 96 * Remove expired log messages and flood control events. | |
| 97 */ | |
| 98 function dblog_cron() { | |
| 99 // Cleanup the watchdog table | |
| 100 $max = db_result(db_query('SELECT MAX(wid) FROM {watchdog}')); | |
| 101 db_query('DELETE FROM {watchdog} WHERE wid < %d', $max - variable_get('dblog_row_limit', 1000)); | |
| 102 } | |
| 103 | |
| 104 /** | |
| 105 * Implementation of hook_user(). | |
| 106 */ | |
| 107 function dblog_user($op, &$edit, &$user) { | |
| 108 if ($op == 'delete') { | |
| 109 db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 function _dblog_get_message_types() { | |
| 114 $types = array(); | |
| 115 | |
| 116 $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type'); | |
| 117 while ($object = db_fetch_object($result)) { | |
| 118 $types[] = $object->type; | |
| 119 } | |
| 120 | |
| 121 return $types; | |
| 122 } | |
| 123 | |
| 124 function dblog_watchdog($log = array()) { | |
| 125 $current_db = db_set_active(); | |
| 126 db_query("INSERT INTO {watchdog} | |
| 127 (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) | |
| 128 VALUES | |
| 129 (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", | |
| 130 $log['user']->uid, | |
| 131 $log['type'], | |
| 132 $log['message'], | |
| 133 serialize($log['variables']), | |
| 134 $log['severity'], | |
| 135 $log['link'], | |
| 136 $log['request_uri'], | |
| 137 $log['referer'], | |
| 138 $log['ip'], | |
| 139 $log['timestamp']); | |
| 140 | |
| 141 if ($current_db) { | |
| 142 db_set_active($current_db); | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 /** | |
| 147 * Theme dblog administration filter selector. | |
| 148 * | |
| 149 * @ingroup themeable | |
| 150 */ | |
| 151 function theme_dblog_filters($form) { | |
| 152 $output = ''; | |
| 153 foreach (element_children($form['status']) as $key) { | |
| 154 $output .= drupal_render($form['status'][$key]); | |
| 155 } | |
| 156 $output .= '<div id="dblog-admin-buttons">'. drupal_render($form['buttons']) .'</div>'; | |
| 157 return $output; | |
| 158 } | |
| 159 |
