/[drupal]/drupal/modules/dblog/dblog.module
ViewVC logotype

Contents of /drupal/modules/dblog/dblog.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.44 - (show annotations) (download) (as text)
Fri Oct 23 22:24:13 2009 UTC (4 weeks, 3 days ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.43: +2 -2 lines
File MIME type: text/x-php
#600974 by effulgentsia, JohnAlbin, sun, and Damien Tournoud: Allow theme functions to take one argument without any hacks. NOTE: This is an API change in hook_theme().
1 <?php
2 // $Id: dblog.module,v 1.43 2009/10/09 00:59:56 dries 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 * Implement 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 * Implement hook_theme().
32 */
33 function dblog_theme() {
34 return array(
35 'dblog_filters' => array(
36 'render element' => 'form',
37 ),
38 );
39 }
40
41 /**
42 * Implement hook_menu().
43 */
44 function dblog_menu() {
45 $items['admin/reports/dblog'] = array(
46 'title' => 'Recent log entries',
47 'description' => 'View events that have recently been logged.',
48 'page callback' => 'dblog_overview',
49 'access arguments' => array('access site reports'),
50 'weight' => -1,
51 'file' => 'dblog.admin.inc',
52 );
53 $items['admin/reports/page-not-found'] = array(
54 'title' => "Top 'page not found' errors",
55 'description' => "View 'page not found' errors (404s).",
56 'page callback' => 'dblog_top',
57 'page arguments' => array('page not found'),
58 'access arguments' => array('access site reports'),
59 'file' => 'dblog.admin.inc',
60 );
61 $items['admin/reports/access-denied'] = array(
62 'title' => "Top 'access denied' errors",
63 'description' => "View 'access denied' errors (403s).",
64 'page callback' => 'dblog_top',
65 'page arguments' => array('access denied'),
66 'access arguments' => array('access site reports'),
67 'file' => 'dblog.admin.inc',
68 );
69 $items['admin/reports/event/%'] = array(
70 'title' => 'Details',
71 'page callback' => 'dblog_event',
72 'page arguments' => array(3),
73 'access arguments' => array('access site reports'),
74 'type' => MENU_CALLBACK,
75 'file' => 'dblog.admin.inc',
76 );
77 return $items;
78 }
79
80 function dblog_init() {
81 if (arg(0) == 'admin' && arg(1) == 'reports') {
82 // Add the CSS for this module
83 drupal_add_css(drupal_get_path('module', 'dblog') . '/dblog.css', array('preprocess' => FALSE));
84 }
85 }
86
87
88
89 /**
90 * Implement hook_cron().
91 *
92 * Remove expired log messages and flood control events.
93 */
94 function dblog_cron() {
95 // Cleanup the watchdog table
96 if (variable_get('dblog_row_limit', 1000) > 0) {
97 $max = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
98 db_delete('watchdog')
99 ->condition('wid', $max - variable_get('dblog_row_limit', 1000), '<=')
100 ->execute();
101 }
102 }
103
104 /**
105 * Implement hook_user_cancel().
106 */
107 function dblog_user_cancel($edit, $account, $method) {
108 switch ($method) {
109 case 'user_cancel_reassign':
110 db_update('watchdog')
111 ->fields(array('uid' => 0))
112 ->condition('uid', $account->uid)
113 ->execute();
114 break;
115
116 case 'user_cancel_delete':
117 db_delete('watchdog')
118 ->condition('uid', $account->uid)
119 ->execute();
120 break;
121 }
122 }
123
124 function _dblog_get_message_types() {
125 $types = array();
126
127 $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
128 foreach ($result as $object) {
129 $types[] = $object->type;
130 }
131
132 return $types;
133 }
134
135 /**
136 * Implement hook_watchdog().
137 *
138 * Note some values may be truncated for database column size restrictions.
139 */
140 function dblog_watchdog(array $log_entry) {
141 Database::getConnection('default', 'default')->insert('watchdog')
142 ->fields(array(
143 'uid' => $log_entry['user']->uid,
144 'type' => substr($log_entry['type'], 0, 64),
145 'message' => $log_entry['message'],
146 'variables' => serialize($log_entry['variables']),
147 'severity' => $log_entry['severity'],
148 'link' => substr($log_entry['link'], 0, 255),
149 'location' => $log_entry['request_uri'],
150 'referer' => $log_entry['referer'],
151 'hostname' => substr($log_entry['ip'], 0, 128),
152 'timestamp' => $log_entry['timestamp'],
153 ))
154 ->execute();
155 }
156
157 /**
158 * Implement hook_form_FORM_ID_alter().
159 */
160 function dblog_form_system_logging_settings_alter(&$form, $form_state) {
161 $form['dblog_row_limit'] = array(
162 '#type' => 'select',
163 '#title' => t('Database log entries to keep'),
164 '#default_value' => variable_get('dblog_row_limit', 1000),
165 '#options' => array(0 => t('All')) + drupal_map_assoc(array(100, 1000, 10000, 100000, 1000000)),
166 '#description' => t('The maximum number of entries to keep in the database log. Requires a <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status')))
167 );
168 $form['buttons']['#weight'] = 1;
169 }
170
171 /**
172 * Theme dblog administration filter selector.
173 *
174 * @ingroup themeable
175 */
176 function theme_dblog_filters($variables) {
177 $form = $variables['form'];
178 $output = '';
179
180 foreach (element_children($form['status']) as $key) {
181 $output .= drupal_render($form['status'][$key]);
182 }
183 $output .= '<div id="dblog-admin-buttons">' . drupal_render($form['buttons']) . '</div>';
184 return $output;
185 }

  ViewVC Help
Powered by ViewVC 1.1.2