Index: mailhandler.admin.inc
===================================================================
diff -u -r1.1.2.20 mailhandler.admin.inc
--- mailhandler.admin.inc	28 Jan 2011 11:09:12 -0000	1.1.2.20
+++ mailhandler.admin.inc	30 Jan 2011 15:12:37 -0000
@@ -390,6 +390,14 @@
     '#default_value' => variable_get('mailhandler_default_encoding', 'UTF-8'),
   );
 
+  $form['mailhandler_watchdog_level'] = array(
+    '#title' => t('Recorded events severity'),
+    '#type' => 'select',
+    '#options' => watchdog_severity_levels(),
+    '#description' => t('Mailhandler will record messages to the selected facility for levels including Emergency up to the selected value here. For more information about the meaning of each category visit !link', array('!link' => l('severity levels defined in RFC 3164, section 4.1.1', 'http://www.faqs.org/rfcs/rfc3164.html'))),
+    '#default_value' => variable_get('mailhandler_watchdog_level', 6),
+  );
+
   $form['#validate'][] = 'mailhandler_admin_settings_validate';
 
   return system_settings_form($form);
Index: mailhandler.install
===================================================================
diff -u -r1.7.2.5 mailhandler.install
--- mailhandler.install	27 Jan 2011 21:32:23 -0000	1.7.2.5
+++ mailhandler.install	30 Jan 2011 14:45:33 -0000
@@ -21,6 +21,18 @@
  * Implementation of hook_uninstall().
  */
 function mailhandler_uninstall() {
+  // Remove module variables.
+  $variables = array(
+    'mailhandler_default_type',
+    'mailhandler_max_retrieval',
+    'mailhandler_default_encoding',
+    'mailhandler_watchdog_level'
+  );
+
+  foreach ($variables as $varname) {
+    variable_del($varname);
+  }
+
   drupal_uninstall_schema('mailhandler');
 }
 
Index: mailhandler.module
===================================================================
diff -u -r1.96.2.37 mailhandler.module
--- mailhandler.module	28 Jan 2011 11:09:12 -0000	1.96.2.37
+++ mailhandler.module	30 Jan 2011 15:12:23 -0000
@@ -182,6 +182,40 @@
   }
 }
 
+/**
+ * Mailhandler general purpose functions.
+ *
+ * The functions included here are helpers for the module operation.
+ */
+
+/**
+ * Log a Mailhandler message.
+ *
+ * This is a wrapper call to watchdog, to avoid selective events recording from
+ * the Mailhandler configuration.
+ *
+ * @param $message
+ *   The message to store in the log. See t() for documentation
+ *   on how $message and $variables interact. Keep $message
+ *   translatable by not concatenating dynamic values into it!
+ * @param $variables
+ *   Array of variables to replace in the message on display or
+ *   NULL if message is already translated or not possible to
+ *   translate.
+ * @param $severity
+ *   The severity of the message, as per RFC 3164. Possible values are
+ *   WATCHDOG_ERROR, WATCHDOG_WARNING, etc.
+ * @param $link
+ *   A link to associate with the message.
+ *
+ * @see watchdog_severity_levels()
+ * @see watchdog()
+ */
+function mailhandler_watchdog_record($message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
+  if ($severity <= variable_get('mailhandler_watchdog_level', 6)) {
+    watchdog('mailhandler', $message, $variables, $severity, $link);
+  }
+}
 
 /**
  * Mailhandler Mailbox database operation.
Index: mailhandler.test
===================================================================
diff -u -r1.1.2.4 mailhandler.test
--- mailhandler.test	28 Jan 2011 11:06:01 -0000	1.1.2.4
+++ mailhandler.test	30 Jan 2011 15:17:11 -0000
@@ -247,12 +247,14 @@
     $this->assertfieldByName('mailhandler_default_type',     'story');
     $this->assertfieldByName('mailhandler_max_retrieval',    '0');
     $this->assertfieldByName('mailhandler_default_encoding', 'UTF-8');
+    $this->assertfieldByName('mailhandler_watchdog_level',   '6');
 
     // Change settings
     $settings = array(
       'mailhandler_default_type'     => 'page',
       'mailhandler_max_retrieval'    => '5',
       'mailhandler_default_encoding' => 'UTF-1',
+      'mailhandler_watchdog_level'   => '1',
     );
     $this->drupalPost(NULL, $settings, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'));
@@ -277,6 +279,7 @@
     $this->assertfieldByName('mailhandler_default_type', $settings['mailhandler_default_type']);
     $this->assertfieldByName('mailhandler_max_retrieval', $settings['mailhandler_max_retrieval']);
     $this->assertfieldByName('mailhandler_default_encoding', $settings['mailhandler_default_encoding']);
+    $this->assertfieldByName('mailhandler_watchdog_level', $settings['mailhandler_watchdog_level']);
   }
 
   /**

