Skip to content
dblog.module 6.08 KiB
Newer Older
Dries Buytaert's avatar
 
Dries Buytaert committed
<?php
Dries Buytaert's avatar
Dries Buytaert committed

Dries Buytaert's avatar
 
Dries Buytaert committed
/**
 * @file
 * System monitoring and logging for administrators.
 *
 * The dblog module monitors your site and keeps a list of
Dries Buytaert's avatar
 
Dries Buytaert committed
 * recorded events containing usage and performance data, errors,
 * warnings, and similar operational information.
 *
Dries Buytaert's avatar
 
Dries Buytaert committed
 */

function dblog_help($path, $arg) {
  switch ($path) {
      $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>';
      $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>';
      $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>';
    case 'admin/reports/dblog':
      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>';
Dries Buytaert's avatar
 
Dries Buytaert committed
  }
Dries Buytaert's avatar
 
Dries Buytaert committed
/**
Dries Buytaert's avatar
 
Dries Buytaert committed
 */
  $items['admin/reports/dblog'] = array(
    'title' => 'Recent log entries',
    'description' => 'View events that have recently been logged.',
    'access arguments' => array('access site reports'),
  $items['admin/reports/page-not-found'] = array(
    'title' => "Top 'page not found' errors",
    'description' => "View 'page not found' errors (404s).",
    'page arguments' => array('page not found'),
    'access arguments' => array('access site reports'),
  $items['admin/reports/access-denied'] = array(
    'title' => "Top 'access denied' errors",
    'description' => "View 'access denied' errors (403s).",
    'page arguments' => array('access denied'),
    'access arguments' => array('access site reports'),
  $items['admin/reports/event/%'] = array(
    'access arguments' => array('access site reports'),
Dries Buytaert's avatar
 
Dries Buytaert committed

    drupal_add_css(drupal_get_path('module', 'dblog') . '/dblog.css', array('preprocess' => FALSE));
Dries Buytaert's avatar
 
Dries Buytaert committed
}

Dries Buytaert's avatar
 
Dries Buytaert committed
 * Remove expired log messages and flood control events.
function dblog_cron() {
  // Cleanup the watchdog table
  if (variable_get('dblog_row_limit', 1000) > 0) {
    $max = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
    db_delete('watchdog')
      ->condition('wid', $max - variable_get('dblog_row_limit', 1000), '<=')
      ->execute();
  }
Dries Buytaert's avatar
 
Dries Buytaert committed
}
Dries Buytaert's avatar
Dries Buytaert committed

function dblog_user_cancel($edit, $account, $method) {
  switch ($method) {
    case 'user_cancel_reassign':
      db_update('watchdog')
        ->fields(array('uid' => 0))
        ->condition('uid', $account->uid)
        ->execute();
      db_delete('watchdog')
        ->condition('uid', $account->uid)
        ->execute();
Dries Buytaert's avatar
 
Dries Buytaert committed
  $types = array();

  $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
Dries Buytaert's avatar
 
Dries Buytaert committed
    $types[] = $object->type;
  }

  return $types;
}
 *
 * Note some values may be truncated for database column size restrictions.
 */
function dblog_watchdog(array $log_entry) {
  Database::getConnection('default', 'default')->insert('watchdog')
      'uid' => $log_entry['user']->uid,
      'type' => substr($log_entry['type'], 0, 64),
      'message' => $log_entry['message'],
      'variables' => serialize($log_entry['variables']),
      'severity' => $log_entry['severity'],
      'link' => substr($log_entry['link'], 0, 255),
      'location' => $log_entry['request_uri'],
      'referer' => $log_entry['referer'],
      'hostname' => substr($log_entry['ip'], 0, 128),
      'timestamp' => $log_entry['timestamp'],
/**
 * Implement hook_form_FORM_ID_alter().
 */
function dblog_form_system_logging_settings_alter(&$form, $form_state) {
  $form['dblog_row_limit'] = array(
    '#type' => 'select',
    '#title' => t('Database log entries to keep'),
    '#default_value' => variable_get('dblog_row_limit', 1000),
    '#options' => array(0 => t('All')) + drupal_map_assoc(array(100, 1000, 10000, 100000, 1000000)),
    '#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')))
  );
  $form['buttons']['#weight'] = 1;
}

/**
 * Theme dblog administration filter selector.
function theme_dblog_filters($variables) {
  $form = $variables['form'];
  foreach (element_children($form['status']) as $key) {
    $output .= drupal_render($form['status'][$key]);
  }
  $output .= '<div id="dblog-admin-buttons">' . drupal_render($form['buttons']) . '</div>';