--- mongodb_watchdog/mongodb_watchdog.module	2010-03-14 00:38:03.000000000 +0000
+++ mongodb_watchdog/mongodb_watchdog.module.new	2010-03-14 00:36:48.000000000 +0000
@@ -48,6 +48,39 @@ function mongodb_watchdog_form_system_lo
     '#default_value' => variable_get('mongodb_watchdog_collectionname', 'watchdog'),
     '#description' => t('In which collection should the watchdog be stored'),
   );
+  $form['mongodb_watchdog']['mongodb_watchdog_size'] = array(
+    '#title' => t('Maximum size of the collection.'),
+    '#type' => 'select',
+    '#default_value' => variable_get('mongodb_watchdog_size', 100000),
+    '#options' => array(0 => t('Unlimited')) + drupal_map_assoc(array(1000, 10000, 100000, 1000000, 10000000)),
+    '#description' => t('The maximum size of the collection in bytes.  Old entries will be dropped.  Select 0 to keep all entries.'),
+  );
+  $form['mongodb_watchdog']['mongodb_watchdog_row_limit'] = array(
+    '#title' => t('MongoDB log entries to keep'),
+    '#type' => 'select',
+    '#default_value' => variable_get('mongodb_watchdog_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.  Old entries will be dropped.  Select 0 to keep all entries.  To cap by number of items, you must also set a maximum size of the collection.'),
+  );
+  $form['#submit'][] = 'mongodb_watchdog_form_system_logging_settings_submit';
+}
+
+/**
+ * Submit handler for mongodb watchdog settings.
+ */
+function mongodb_watchdog_form_system_logging_settings_submit(&$form, &$form_state) {
+  // if the row limit changed drop the old collection and setup a new with limited rows.
+  if (($form_state['values']['mongodb_watchdog_row_limit'] != variable_get('mongodb_watchdog_row_limit', 1000))
+    || ($form_state['values']['mongodb_watchdog_size'] != variable_get('mongodb_watchdog_size', 10000))) {
+    $collection = mongodb_collection(variable_get('mongodb_collectionname', 'watchdog'));
+    $collection->db->dropCollection($collection_name);
+    if ($form_state['values']['mongodb_watchdog_size'] && $form_state['values']['mongodb_watchdog_row_limit']) {
+      $collection->db->createCollection($collection_name, TRUE, $form_state['values']['mongodb_watchdog_size'], $form_state['values']['mongodb_watchdog_row_limit']);
+    }
+    else {
+      $collection->db->createCollection($collection_name);
+    }
+  }
 }
 
 /**
