Newer
Older
// $Id$
Dries Buytaert
committed
* The dblog module monitors your site and keeps a list of
* recorded events containing usage and performance data, errors,
* warnings, and similar operational information.
*
Gábor Hojtsy
committed
* @see watchdog()
/**
* Implementation of hook_help().
*/
Gábor Hojtsy
committed
function dblog_help($path, $arg) {
switch ($path) {
Dries Buytaert
committed
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>';
Gábor Hojtsy
committed
$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>';
Dries Buytaert
committed
return $output;
case 'admin/reports/dblog':
Dries Buytaert
committed
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
committed
/**
* Implementation of hook_theme()
*/
Dries Buytaert
committed
function dblog_theme() {
Dries Buytaert
committed
return array(
Dries Buytaert
committed
'dblog_filters' => array(
Dries Buytaert
committed
'arguments' => array('form' => NULL),
),
);
}
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.',
Dries Buytaert
committed
'page callback' => 'drupal_get_form',
'page arguments' => array('dblog_admin_settings'),
'file' => 'dblog.admin.inc',
Dries Buytaert
committed
);
$items['admin/reports/dblog'] = array(
'title' => 'Recent log entries',
'description' => 'View events that have recently been logged.',
Dries Buytaert
committed
'page callback' => 'dblog_overview',
Dries Buytaert
committed
'weight' => -1,
'file' => 'dblog.admin.inc',
Dries Buytaert
committed
);
$items['admin/reports/page-not-found'] = array(
'title' => "Top 'page not found' errors",
'description' => "View 'page not found' errors (404s).",
Dries Buytaert
committed
'page callback' => 'dblog_top',
Dries Buytaert
committed
'page arguments' => array('page not found'),
'file' => 'dblog.admin.inc',
Dries Buytaert
committed
);
$items['admin/reports/access-denied'] = array(
'title' => "Top 'access denied' errors",
'description' => "View 'access denied' errors (403s).",
Dries Buytaert
committed
'page callback' => 'dblog_top',
Dries Buytaert
committed
'page arguments' => array('access denied'),
'file' => 'dblog.admin.inc',
Dries Buytaert
committed
);
$items['admin/reports/event/%'] = array(
'title' => 'Details',
Dries Buytaert
committed
'page callback' => 'dblog_event',
Dries Buytaert
committed
'page arguments' => array(3),
Dries Buytaert
committed
'type' => MENU_CALLBACK,
'file' => 'dblog.admin.inc',
Dries Buytaert
committed
);
return $items;
}
Dries Buytaert
committed
function dblog_init() {
Gábor Hojtsy
committed
if (arg(0) == 'admin' && arg(1) == 'reports') {
Dries Buytaert
committed
// Add the CSS for this module
Dries Buytaert
committed
drupal_add_css(drupal_get_path('module', 'dblog') .'/dblog.css', 'module', 'all', FALSE);
Dries Buytaert
committed
/**
* Implementation of hook_cron().
*
Dries Buytaert
committed
function dblog_cron() {
// Cleanup the watchdog table
Dries Buytaert
committed
$max = db_result(db_query('SELECT MAX(wid) FROM {watchdog}'));
Gábor Hojtsy
committed
db_query('DELETE FROM {watchdog} WHERE wid <= %d', $max - variable_get('dblog_row_limit', 1000));
Gerhard Killesreiter
committed
/**
* Implementation of hook_user().
*/
Dries Buytaert
committed
function dblog_user($op, &$edit, &$user) {
Gerhard Killesreiter
committed
if ($op == 'delete') {
db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
Gerhard Killesreiter
committed
}
}
Dries Buytaert
committed
function _dblog_get_message_types() {
$result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
while ($object = db_fetch_object($result)) {
$types[] = $object->type;
}
return $types;
}
Dries Buytaert
committed
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)
Dries Buytaert
committed
VALUES
(%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)",
Dries Buytaert
committed
$log['user']->uid,
$log['type'],
$log['message'],
serialize($log['variables']),
Dries Buytaert
committed
$log['severity'],
$log['link'],
$log['request_uri'],
$log['referer'],
$log['ip'],
$log['timestamp']);
if ($current_db) {
db_set_active($current_db);
}
}
Dries Buytaert
committed
/**
* Theme dblog administration filter selector.
Gábor Hojtsy
committed
*
* @ingroup themeable
Dries Buytaert
committed
*/
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;
}