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

Line #Times calledCode
1
<?php
2
// $Id: dblog.module,v 1.30 2008/10/30 09:16:01 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
 */
182366
function dblog_help($path, $arg) {
19
  switch ($path) {
201678
    case 'admin/help#dblog':
2120
      $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>';
2220
      $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>';
2320
      $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>';
2420
      return $output;
251676
    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
  }
281670
}
29
30
/**
31
 * Implementation of hook_theme().
32
 */
332366
function dblog_theme() {
34
  return array(
35
    'dblog_filters' => array(
36178
      'arguments' => array('form' => NULL),
37178
    ),
38178
  );
390
}
40
41
/**
42
 * Implementation of hook_menu().
43
 */
442366
function dblog_menu() {
45162
  $items['admin/settings/logging/dblog'] = array(
46162
    'title' => 'Database logging',
47162
    '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.',
48162
    'page callback' => 'drupal_get_form',
49162
    'page arguments' => array('dblog_admin_settings'),
50162
    'access arguments' => array('administer site configuration'),
51
  );
52162
  $items['admin/reports/dblog'] = array(
53162
    'title' => 'Recent log entries',
54162
    'description' => 'View events that have recently been logged.',
55162
    'page callback' => 'dblog_overview',
56162
    'access arguments' => array('access site reports'),
57162
    'weight' => -1,
58
  );
59162
  $items['admin/reports/page-not-found'] = array(
60162
    'title' => "Top 'page not found' errors",
61162
    'description' => "View 'page not found' errors (404s).",
62162
    'page callback' => 'dblog_top',
63162
    'page arguments' => array('page not found'),
64162
    'access arguments' => array('access site reports'),
65
  );
66162
  $items['admin/reports/access-denied'] = array(
67162
    'title' => "Top 'access denied' errors",
68162
    'description' => "View 'access denied' errors (403s).",
69162
    'page callback' => 'dblog_top',
70162
    'page arguments' => array('access denied'),
71162
    'access arguments' => array('access site reports'),
72
  );
73162
  $items['admin/reports/event/%'] = array(
74162
    'title' => 'Details',
75162
    'page callback' => 'dblog_event',
76162
    'page arguments' => array(3),
77162
    'access arguments' => array('access site reports'),
78162
    'type' => MENU_CALLBACK,
79
  );
80162
  return $items;
810
}
82
832366
function dblog_init() {
842366
  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',
array('preprocess' => FALSE));
8729
  }
882366
}
89
90
91
92
/**
93
 * Implementation of hook_cron().
94
 *
95
 * Remove expired log messages and flood control events.
96
 */
972366
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_delete().
105
 */
1062366
function dblog_user_delete(&$edit, &$user) {
1072
  db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
1082
}
109
1102366
function _dblog_get_message_types() {
1116
  $types = array();
112
1136
  $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY
type');
1146
  while ($object = db_fetch_object($result)) {
1156
    $types[] = $object->type;
1166
  }
117
1186
  return $types;
1190
}
120
1212366
function dblog_watchdog($log = array()) {
122704
  Database::getConnection('default')->insert('watchdog')
123704
    ->fields(array(
124704
      'uid' => $log['user']->uid,
125704
      'type' => $log['type'],
126704
      'message' => $log['message'],
127704
      'variables' => serialize($log['variables']),
128704
      'severity' => $log['severity'],
129704
      'link' => $log['link'],
130704
      'location' => $log['request_uri'],
131704
      'referer' => $log['referer'],
132704
      'hostname' => $log['ip'],
133704
      'timestamp' => $log['timestamp'],
134704
    ))
135704
    ->execute();
136704
}
137
138
/**
139
 * Theme dblog administration filter selector.
140
 *
141
 * @ingroup themeable
142
 */
1432366
function theme_dblog_filters($form) {
1446
  $output = '';
1456
  foreach (element_children($form['status']) as $key) {
1466
    $output .= drupal_render($form['status'][$key]);
1476
  }
1486
  $output .= '<div id="dblog-admin-buttons">' .
drupal_render($form['buttons']) . '</div>';
1496
  return $output;
1500
}
151
1522366