diff --git a/core/includes/common.inc b/core/includes/common.inc
index 0b17746..7fe6a60 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4046,6 +4046,7 @@ function drupal_add_js($data = NULL, $options = NULL) {
           'data' => array(
             array('basePath' => base_path()),
             array('pathPrefix' => empty($prefix) ? '' : $prefix),
+            array('errorLevel' => (integer) variable_get('error_level', 2)),
           ),
           'type' => 'setting',
           'scope' => 'header',
diff --git a/core/misc/ajax.js b/core/misc/ajax.js
index 652b8e2..b012414 100644
--- a/core/misc/ajax.js
+++ b/core/misc/ajax.js
@@ -259,7 +259,7 @@ Drupal.ajax.prototype.eventResponse = function (element, event) {
     // Unset the ajax.ajaxing flag here because it won't be unset during
     // the complete response.
     ajax.ajaxing = false;
-    alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message);
+    Drupal.log("An error occurred while attempting to process " + ajax.options.url + ": " + e.message, 'error');
   }
 
   // For radio/checkbox, allow the default event. On IE, this means letting
@@ -448,7 +448,7 @@ Drupal.ajax.prototype.getEffect = function (response) {
  * Handler for the form redirection error.
  */
 Drupal.ajax.prototype.error = function (response, uri) {
-  alert(Drupal.ajaxError(response, uri));
+  Drupal.log(Drupal.ajaxError(response, uri), 'error');
   // Remove the progress element.
   if (this.progress.element) {
     $(this.progress.element).remove();
diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js
index 2f4e5f6..a310f18 100644
--- a/core/misc/autocomplete.js
+++ b/core/misc/autocomplete.js
@@ -309,7 +309,7 @@ Drupal.ACDB.prototype.search = function (searchString) {
         }
       },
       error: function (xmlhttp) {
-        alert(Drupal.ajaxError(xmlhttp, db.uri));
+        Drupal.log(Drupal.ajaxError(xmlhttp, db.uri), 'error');
       }
     });
   }, this.delay);
diff --git a/core/misc/drupal.js b/core/misc/drupal.js
index 83b0884..28c8951 100644
--- a/core/misc/drupal.js
+++ b/core/misc/drupal.js
@@ -1,4 +1,3 @@
-
 var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'locale': {} };
 
 // Allow other JavaScript libraries to use $.
@@ -110,6 +109,51 @@ Drupal.detachBehaviors = function (context, settings, trigger) {
 };
 
 /**
+ * TODO description
+ *
+ * Drupal.log(message, 'status');  console.log(message);
+ * Drupal.log(message, 'warning'); console.warn(message);
+ * Drupal.log(message, 'error');   console.error(message);
+ *
+ * Drupal.log(message, 'myType');  console.log('myType', message);
+ */
+Drupal.log = (function () {
+  // Initialisation is done in a closure in case Drupal.log is used in a
+  // demanding loop, inside an onresize function for example.
+
+  // Status from drupal_set_message().
+  var status = ['status', 'warning', 'error'];
+  var settings = Drupal.settings;
+
+  // Map Drupal error level to console object methods.
+  var mapToConsole = {status: 'log', warning: 'warn', error: 'error'};
+  var consoleAvailable = (typeof window['console'] === 'object');
+
+  // Actual logging function
+  return function (message, type) {
+    var customType = null;
+    var args = [];
+    // Checking here allow dynamic error level switching.
+    if (settings.errorLevel !== 0) {
+      type = type || 'status';
+      // index in status table <=> error reporting level
+      var errorLevel = $.inArray(type, status);
+      if (errorLevel === -1) {
+        errorLevel = 0;
+        args.push(type + ':');
+        type = 'status';
+      }
+      if (settings.errorLevel >= errorLevel) {
+        args.push(message);
+        if (consoleAvailable) {
+          console[mapToConsole[type]].apply(this, args);
+        }
+      }
+    }
+  };
+}());
+
+/**
  * Encode special characters in a plain-text string for display as HTML.
  *
  * @ingroup sanitization
diff --git a/core/modules/simpletest/tests/common.test b/core/modules/simpletest/tests/common.test
index 5cb238f..20e611f 100644
--- a/core/modules/simpletest/tests/common.test
+++ b/core/modules/simpletest/tests/common.test
@@ -1235,8 +1235,8 @@ class CommonJavaScriptTestCase extends DrupalWebTestCase {
    */
   function testAddSetting() {
     $javascript = drupal_add_js(array('drupal' => 'rocks', 'dries' => 280342800), 'setting');
-    $this->assertEqual(280342800, $javascript['settings']['data'][2]['dries'], t('JavaScript setting is set correctly.'));
-    $this->assertEqual('rocks', $javascript['settings']['data'][2]['drupal'], t('The other JavaScript setting is set correctly.'));
+    $this->assertEqual(280342800, $javascript['settings']['data'][3]['dries'], t('JavaScript setting is set correctly.'));
+    $this->assertEqual('rocks', $javascript['settings']['data'][3]['drupal'], t('The other JavaScript setting is set correctly.'));
   }
 
   /**
