' . t('About') . ''; $output .= '
' . t('The Database Logging module logs system events in the Drupal database. For more information, see the online documentation for the Database Logging module.', [':dblog' => 'https://www.drupal.org/documentation/modules/dblog']) . '
'; $output .= '' . t('The Database Logging module logs system events in the Drupal database. Monitor your site or debug site problems on this page.') . '
'; } } /** * Implements hook_menu_links_discovered_alter(). */ function dblog_menu_links_discovered_alter(&$links) { if (\Drupal::moduleHandler()->moduleExists('search')) { $links['dblog.search'] = [ 'title' => new TranslatableMarkup('Top search phrases'), 'route_name' => 'dblog.search', 'description' => new TranslatableMarkup('View most popular search phrases.'), 'parent' => 'system.admin_reports', ]; } return $links; } /** * Implements hook_cron(). * * Controls the size of the log table, paring it to 'dblog_row_limit' messages. */ function dblog_cron() { // Cleanup the watchdog table. $row_limit = \Drupal::config('dblog.settings')->get('row_limit'); // For row limit n, get the wid of the nth row in descending wid order. // Counting the most recent n rows avoids issues with wid number sequences, // e.g. auto_increment value > 1 or rows deleted directly from the table. if ($row_limit > 0) { $min_row = db_select('watchdog', 'w') ->fields('w', ['wid']) ->orderBy('wid', 'DESC') ->range($row_limit - 1, 1) ->execute()->fetchField(); // Delete all table entries older than the nth row, if nth row was found. if ($min_row) { db_delete('watchdog') ->condition('wid', $min_row, '<') ->execute(); } } } /** * Gathers a list of uniquely defined database log message types. * * @return array * List of uniquely defined database log message types. */ function _dblog_get_message_types() { return db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type') ->fetchAllKeyed(0, 0); } /** * Implements hook_form_FORM_ID_alter() for system_logging_settings(). */ function dblog_form_system_logging_settings_alter(&$form, FormStateInterface $form_state) { $row_limits = [100, 1000, 10000, 100000, 1000000]; $form['dblog_row_limit'] = [ '#type' => 'select', '#title' => t('Database log messages to keep'), '#default_value' => \Drupal::configFactory()->getEditable('dblog.settings')->get('row_limit'), '#options' => [0 => t('All')] + array_combine($row_limits, $row_limits), '#description' => t('The maximum number of messages to keep in the database log. Requires a cron maintenance task.', [':cron' => \Drupal::url('system.status')]) ]; $form['#submit'][] = 'dblog_logging_settings_submit'; } /** * Form submission handler for system_logging_settings(). * * @see dblog_form_system_logging_settings_alter() */ function dblog_logging_settings_submit($form, FormStateInterface $form_state) { \Drupal::configFactory()->getEditable('dblog.settings')->set('row_limit', $form_state->getValue('dblog_row_limit'))->save(); }