Skip to content
dblog.module 5.44 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
 */

/**
 * Implementation of hook_help().
 */
function dblog_help($path, $arg) {
  switch ($path) {
    case 'admin/help#dblog':
      $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
 * Implementation of hook_menu().
Dries Buytaert's avatar
 
Dries Buytaert committed
 */
function dblog_menu() {
  $items['admin/settings/logging/dblog'] = array(
    'title' => 'Database logging',
    '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.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('dblog_admin_settings'),
Gábor Hojtsy's avatar
Gábor Hojtsy committed
    'access arguments' => array('administer site configuration'),
    'file' => 'dblog.admin.inc',
  $items['admin/reports/dblog'] = array(
    'title' => 'Recent log entries',
    'description' => 'View events that have recently been logged.',
Gábor Hojtsy's avatar
Gábor Hojtsy committed
    'access arguments' => array('access site reports'),
    'file' => 'dblog.admin.inc',
  $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'),
Gábor Hojtsy's avatar
Gábor Hojtsy committed
    'access arguments' => array('access site reports'),
    'file' => 'dblog.admin.inc',
  $items['admin/reports/access-denied'] = array(
    'title' => "Top 'access denied' errors",
    'description' => "View 'access denied' errors (403s).",
    'page arguments' => array('access denied'),
Gábor Hojtsy's avatar
Gábor Hojtsy committed
    'access arguments' => array('access site reports'),
    'file' => 'dblog.admin.inc',
  $items['admin/reports/event/%'] = array(
Gábor Hojtsy's avatar
Gábor Hojtsy committed
    'access arguments' => array('access site reports'),
    'file' => 'dblog.admin.inc',
Dries Buytaert's avatar
 
Dries Buytaert committed

    drupal_add_css(drupal_get_path('module', 'dblog') .'/dblog.css', 'module', 'all', FALSE);
Dries Buytaert's avatar
 
Dries Buytaert committed
}

/**
 * Implementation of hook_cron().
 *
Dries Buytaert's avatar
 
Dries Buytaert committed
 * Remove expired log messages and flood control events.
function dblog_cron() {
  // Cleanup the watchdog table
  $max = db_result(db_query('SELECT MAX(wid) FROM {watchdog}'));
  db_query('DELETE FROM {watchdog} WHERE wid <= %d', $max - variable_get('dblog_row_limit', 1000));
Dries Buytaert's avatar
 
Dries Buytaert committed
}
Dries Buytaert's avatar
Dries Buytaert committed

function dblog_user($op, &$edit, &$user) {
Steven Wittens's avatar
Steven Wittens committed
    db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
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
  while ($object = db_fetch_object($result)) {
    $types[] = $object->type;
  }

  return $types;
}

function dblog_watchdog($log = array()) {
  $current_db = db_set_active();
  db_query("INSERT INTO {watchdog}
    (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
    (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)",
    $log['user']->uid,
    $log['type'],
    $log['message'],
    serialize($log['variables']),
    $log['severity'],
    $log['link'],
    $log['request_uri'],
    $log['referer'],
    $log['ip'],
    $log['timestamp']);

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