dblog.module

You are here

  1. 7 modules/dblog/dblog.module
  2. 6 modules/dblog/dblog.module
  3. 8 core/modules/dblog/dblog.module

System monitoring and logging for administrators.

The dblog module monitors your site and keeps a list of recorded events containing usage and performance data, errors, warnings, and similar operational information.

See also

watchdog()

Functions

Namesort descending Description
dblog_cron Implementation of hook_cron().
dblog_help Implementation of hook_help().
dblog_init
dblog_menu Implementation of hook_menu().
dblog_theme Implementation of hook_theme()
dblog_user Implementation of hook_user().
dblog_watchdog Implementation of hook_watchdog().
theme_dblog_filters Theme dblog administration filter selector.
_dblog_get_message_types

File

modules/dblog/dblog.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * System monitoring and logging for administrators.
  5. *
  6. * The dblog module monitors your site and keeps a list of
  7. * recorded events containing usage and performance data, errors,
  8. * warnings, and similar operational information.
  9. *
  10. * @see watchdog()
  11. */
  12. /**
  13. * Implementation of hook_help().
  14. */
  15. function dblog_help($path, $arg) {
  16. switch ($path) {
  17. case 'admin/help#dblog':
  18. $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>';
  19. $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>';
  20. $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>';
  21. return $output;
  22. case 'admin/reports/dblog':
  23. 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>';
  24. }
  25. }
  26. /**
  27. * Implementation of hook_theme()
  28. */
  29. function dblog_theme() {
  30. return array(
  31. 'dblog_filters' => array(
  32. 'arguments' => array('form' => NULL),
  33. ),
  34. );
  35. }
  36. /**
  37. * Implementation of hook_menu().
  38. */
  39. function dblog_menu() {
  40. $items['admin/settings/logging/dblog'] = array(
  41. 'title' => 'Database logging',
  42. '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.',
  43. 'page callback' => 'drupal_get_form',
  44. 'page arguments' => array('dblog_admin_settings'),
  45. 'access arguments' => array('administer site configuration'),
  46. 'file' => 'dblog.admin.inc',
  47. );
  48. $items['admin/reports/dblog'] = array(
  49. 'title' => 'Recent log entries',
  50. 'description' => 'View events that have recently been logged.',
  51. 'page callback' => 'dblog_overview',
  52. 'access arguments' => array('access site reports'),
  53. 'weight' => -1,
  54. 'file' => 'dblog.admin.inc',
  55. );
  56. $items['admin/reports/page-not-found'] = array(
  57. 'title' => "Top 'page not found' errors",
  58. 'description' => "View 'page not found' errors (404s).",
  59. 'page callback' => 'dblog_top',
  60. 'page arguments' => array('page not found'),
  61. 'access arguments' => array('access site reports'),
  62. 'file' => 'dblog.admin.inc',
  63. );
  64. $items['admin/reports/access-denied'] = array(
  65. 'title' => "Top 'access denied' errors",
  66. 'description' => "View 'access denied' errors (403s).",
  67. 'page callback' => 'dblog_top',
  68. 'page arguments' => array('access denied'),
  69. 'access arguments' => array('access site reports'),
  70. 'file' => 'dblog.admin.inc',
  71. );
  72. $items['admin/reports/event/%'] = array(
  73. 'title' => 'Details',
  74. 'page callback' => 'dblog_event',
  75. 'page arguments' => array(3),
  76. 'access arguments' => array('access site reports'),
  77. 'type' => MENU_CALLBACK,
  78. 'file' => 'dblog.admin.inc',
  79. );
  80. return $items;
  81. }
  82. function dblog_init() {
  83. if (arg(0) == 'admin' && arg(1) == 'reports') {
  84. // Add the CSS for this module
  85. drupal_add_css(drupal_get_path('module', 'dblog') .'/dblog.css', 'module', 'all', FALSE);
  86. }
  87. }
  88. /**
  89. * Implementation of hook_cron().
  90. *
  91. * Remove expired log messages.
  92. */
  93. function dblog_cron() {
  94. // Cleanup the watchdog table
  95. $max = db_result(db_query('SELECT MAX(wid) FROM {watchdog}'));
  96. db_query('DELETE FROM {watchdog} WHERE wid <= %d', $max - variable_get('dblog_row_limit', 1000));
  97. }
  98. /**
  99. * Implementation of hook_user().
  100. */
  101. function dblog_user($op, &$edit, &$user) {
  102. if ($op == 'delete') {
  103. db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
  104. }
  105. }
  106. function _dblog_get_message_types() {
  107. $types = array();
  108. $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
  109. while ($object = db_fetch_object($result)) {
  110. $types[] = $object->type;
  111. }
  112. return $types;
  113. }
  114. /**
  115. * Implementation of hook_watchdog().
  116. */
  117. function dblog_watchdog($log = array()) {
  118. $current_db = db_set_active();
  119. db_query("INSERT INTO {watchdog}
  120. (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
  121. VALUES
  122. (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)",
  123. $log['user']->uid,
  124. $log['type'],
  125. $log['message'],
  126. serialize($log['variables']),
  127. $log['severity'],
  128. $log['link'],
  129. $log['request_uri'],
  130. $log['referer'],
  131. $log['ip'],
  132. $log['timestamp']);
  133. if ($current_db) {
  134. db_set_active($current_db);
  135. }
  136. }
  137. /**
  138. * Theme dblog administration filter selector.
  139. *
  140. * @ingroup themeable
  141. */
  142. function theme_dblog_filters($form) {
  143. $output = '';
  144. foreach (element_children($form['status']) as $key) {
  145. $output .= drupal_render($form['status'][$key]);
  146. }
  147. $output .= '<div id="dblog-admin-buttons">'. drupal_render($form['buttons']) .'</div>';
  148. return $output;
  149. }