Code coverage for /20080809/modules/dblog/dblog.module

Line #Times calledCode
1
<?php
2
// $Id: dblog.module,v 1.26 2008/07/24 16:25:17 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
 * Implementation of hook_help().
17
 */
182027
function dblog_help($path, $arg) {
19
  switch ($path) {
201491
    case 'admin/help#dblog':
2125
      $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>';
2225
      $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>';
2325
      $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>';
2425
      return $output;
251489
    case 'admin/reports/dblog':
266
      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>';
270
  }
281483
}
29
30
/**
31
 * Implementation of hook_theme().
32
 */
332027
function dblog_theme() {
34
  return array(
35
    'dblog_filters' => array(
3691
      'arguments' => array('form' => NULL),
3791
    ),
3891
  );
390
}
40
41
/**
42
 * Implementation of hook_menu().
43
 */
442027
function dblog_menu() {
4586
  $items['admin/settings/logging/dblog'] = array(
4686
    'title' => 'Database logging',
4786
    '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.',
4886
    'page callback' => 'drupal_get_form',
4986
    'page arguments' => array('dblog_admin_settings'),
5086
    'access arguments' => array('administer site configuration'),
51
  );
5286
  $items['admin/reports/dblog'] = array(
5386
    'title' => 'Recent log entries',
5486
    'description' => 'View events that have recently been logged.',
5586
    'page callback' => 'dblog_overview',
5686
    'access arguments' => array('access site reports'),
5786
    'weight' => -1,
58
  );
5986
  $items['admin/reports/page-not-found'] = array(
6086
    'title' => "Top 'page not found' errors",
6186
    'description' => "View 'page not found' errors (404s).",
6286
    'page callback' => 'dblog_top',
6386
    'page arguments' => array('page not found'),
6486
    'access arguments' => array('access site reports'),
65
  );
6686
  $items['admin/reports/access-denied'] = array(
6786
    'title' => "Top 'access denied' errors",
6886
    'description' => "View 'access denied' errors (403s).",
6986
    'page callback' => 'dblog_top',
7086
    'page arguments' => array('access denied'),
7186
    'access arguments' => array('access site reports'),
72
  );
7386
  $items['admin/reports/event/%'] = array(
7486
    'title' => 'Details',
7586
    'page callback' => 'dblog_event',
7686
    'page arguments' => array(3),
7786
    'access arguments' => array('access site reports'),
7886
    'type' => MENU_CALLBACK,
79
  );
8086
  return $items;
810
}
82
832027
function dblog_init() {
842027
  if (arg(0) == 'admin' && arg(1) == 'reports') {
85
    // Add the CSS for this module
8629
    drupal_add_css(drupal_get_path('module', 'dblog') . '/dblog.css',
'module', 'all', FALSE);
8729
  }
882027
}
89
90
91
92
/**
93
 * Implementation of hook_cron().
94
 *
95
 * Remove expired log messages and flood control events.
96
 */
972027
function dblog_cron() {
98
  // Cleanup the watchdog table
992
  $max = db_result(db_query('SELECT MAX(wid) FROM {watchdog}'));
1002
  db_query('DELETE FROM {watchdog} WHERE wid <= %d', $max -
variable_get('dblog_row_limit', 1000));
1012
}
102
103
/**
104
 * Implementation of hook_user().
105
 */
1062027
function dblog_user($op, &$edit, &$user) {
1071848
  if ($op == 'delete') {
1082
    db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
1092
  }
1101848
}
111
1122027
function _dblog_get_message_types() {
1136
  $types = array();
114
1156
  $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY
type');
1166
  while ($object = db_fetch_object($result)) {
1176
    $types[] = $object->type;
1186
  }
119
1206
  return $types;
1210
}
122
1232027
function dblog_watchdog($log = array()) {
124540
  $current_db = db_set_active();
125540
  db_query("INSERT INTO {watchdog}
126
    (uid, type, message, variables, severity, link, location, referer,
hostname, timestamp)
127
    VALUES
128540
    (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)",
129540
    $log['user']->uid,
130540
    $log['type'],
131540
    $log['message'],
132540
    serialize($log['variables']),
133540
    $log['severity'],
134540
    $log['link'],
135540
    $log['request_uri'],
136540
    $log['referer'],
137540
    $log['ip'],
138540
    $log['timestamp']);
139
140540
  if ($current_db) {
141540
    db_set_active($current_db);
142540
  }
143540
}
144
145
/**
146
 * Theme dblog administration filter selector.
147
 *
148
 * @ingroup themeable
149
 */
1502027
function theme_dblog_filters($form) {
1516
  $output = '';
1526
  foreach (element_children($form['status']) as $key) {
1536
    $output .= drupal_render($form['status'][$key]);
1546
  }
1556
  $output .= '<div id="dblog-admin-buttons">' .
drupal_render($form['buttons']) . '</div>';
1566
  return $output;
1570
}
158
1592027