diff --git a/core/includes/common.inc b/core/includes/common.inc
index a8ad43a..3b91573 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -1,6 +1,7 @@
 <?php
 
 use Drupal\Component\Utility\Crypt;
+use Drupal\Component\Utility\Debug;
 use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\UrlValidator;
 use Drupal\Component\Utility\Xss;
@@ -5914,15 +5915,11 @@ function _drupal_flush_css_js() {
  *   Flag to switch between print_r() and var_export() for data conversion to
  *   string. Set $print_r to TRUE when dealing with a recursive data structure
  *   as var_export() will generate an error.
+ *
+ * @see \Drupal\Component\Utility\Debug::debug().
  */
 function debug($data, $label = NULL, $print_r = FALSE) {
-  // Print $data contents to string.
-  $string = check_plain($print_r ? print_r($data, TRUE) : var_export($data, TRUE));
-
-  // Display values with pre-formatting to increase readability.
-  $string = '<pre>' . $string . '</pre>';
-
-  trigger_error(trim($label ? "$label: $string" : $string));
+  Debug::output($data, $label, $print_r);
 }
 
 /**
diff --git a/core/includes/utility.inc b/core/includes/utility.inc
index f651fd6..6ec27ea 100644
--- a/core/includes/utility.inc
+++ b/core/includes/utility.inc
@@ -5,6 +5,8 @@
  * Miscellaneous functions.
  */
 
+use Drupal\Component\Utility\Debug;
+
 /**
  * Drupal-friendly var_export().
  *
@@ -15,52 +17,9 @@
  *
  * @return
  *   The variable exported in a way compatible to Drupal's coding standards.
+ *
+ * @see \Drupal\Component\Utility\Debug::varExport().
  */
 function drupal_var_export($var, $prefix = '') {
-  if (is_array($var)) {
-    if (empty($var)) {
-      $output = 'array()';
-    }
-    else {
-      $output = "array(\n";
-      // Don't export keys if the array is non associative.
-      $export_keys = array_values($var) != $var;
-      foreach ($var as $key => $value) {
-        $output .= '  ' . ($export_keys ? drupal_var_export($key) . ' => ' : '') . drupal_var_export($value, '  ', FALSE) . ",\n";
-      }
-      $output .= ')';
-    }
-  }
-  elseif (is_bool($var)) {
-    $output = $var ? 'TRUE' : 'FALSE';
-  }
-  elseif (is_string($var)) {
-    $line_safe_var = str_replace("\n", '\n', $var);
-    if (strpos($var, "\n") !== FALSE || strpos($var, "'") !== FALSE) {
-      // If the string contains a line break or a single quote, use the
-      // double quote export mode. Encode backslash and double quotes and
-      // transform some common control characters.
-      $var = str_replace(array('\\', '"', "\n", "\r", "\t"), array('\\\\', '\"', '\n', '\r', '\t'), $var);
-      $output = '"' . $var . '"';
-    }
-    else {
-      $output = "'" . $var . "'";
-    }
-  }
-  elseif (is_object($var) && get_class($var) === 'stdClass') {
-    // var_export() will export stdClass objects using an undefined
-    // magic method __set_state() leaving the export broken. This
-    // workaround avoids this by casting the object as an array for
-    // export and casting it back to an object when evaluated.
-    $output = '(object) ' . drupal_var_export((array) $var, $prefix);
-  }
-  else {
-    $output = var_export($var, TRUE);
-  }
-
-  if ($prefix) {
-    $output = str_replace("\n", "\n$prefix", $output);
-  }
-
-  return $output;
+  return Debug::varExport($var, $prefix);
 }
diff --git a/core/lib/Drupal/Component/Utility/Debug.php b/core/lib/Drupal/Component/Utility/Debug.php
new file mode 100644
index 0000000..c5390b6
--- /dev/null
+++ b/core/lib/Drupal/Component/Utility/Debug.php
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Component\Utility\Debug.
+ */
+
+namespace Drupal\Component\Utility;
+
+/**
+ * Provides a component with some helpful methods for debugging.
+ */
+class Debug {
+
+  /**
+   * Provides a more Drupal-friendly var_export().
+   *
+   * @param mixed $var
+   *   The variable to export.
+   * @param string $prefix
+   *   A prefix that will be added at the beginning of every lines of the output.
+   *
+   * @return string
+   *   The variable exported in a way compatible to Drupal's coding standards.
+   */
+  public static function varExport($var, $prefix = '') {
+    if (is_array($var)) {
+      if (empty($var)) {
+        $output = 'array()';
+      }
+      else {
+        $output = "array(\n";
+        // Don't export keys if the array is non associative.
+        $export_keys = array_values($var) != $var;
+        foreach ($var as $key => $value) {
+          $output .= '  ' . ($export_keys ? static::varExport($key) . ' => ' : '') . static::varExport($value, '  ', FALSE) . ",\n";
+        }
+        $output .= ')';
+      }
+    }
+    elseif (is_bool($var)) {
+      $output = $var ? 'TRUE' : 'FALSE';
+    }
+    elseif (is_string($var)) {
+      $line_safe_var = str_replace("\n", '\n', $var);
+      if (strpos($var, "\n") !== FALSE || strpos($var, "'") !== FALSE) {
+        // If the string contains a line break or a single quote, use the
+        // double quote export mode. Encode backslash and double quotes and
+        // transform some common control characters.
+        $var = str_replace(array('\\', '"', "\n", "\r", "\t"), array('\\\\', '\"', '\n', '\r', '\t'), $var);
+        $output = '"' . $var . '"';
+      }
+      else {
+        $output = "'" . $var . "'";
+      }
+    }
+    elseif (is_object($var) && get_class($var) === 'stdClass') {
+      // var_export() will export stdClass objects using an undefined
+      // magic method __set_state() leaving the export broken. This
+      // workaround avoids this by casting the object as an array for
+      // export and casting it back to an object when evaluated.
+      $output = '(object) ' . static::varExport((array) $var, $prefix);
+    }
+    else {
+      $output = var_export($var, TRUE);
+    }
+
+    if ($prefix) {
+      $output = str_replace("\n", "\n$prefix", $output);
+    }
+
+    return $output;
+  }
+
+  /**
+   * Outputs debug information.
+   *
+   * The debug information is passed on to trigger_error() after being converted
+   * to a string using _drupal_debug_message().
+   *
+   * @param mixed $data
+   *   Data to be output.
+   * @param string $label
+   *   Label to prefix the data.
+   * @param bool $print_r
+   *   Flag to switch between print_r() and var_export() for data conversion to
+   *   string. Set $print_r to TRUE when dealing with a recursive data structure
+   *   as var_export() will generate an error.
+   */
+  public static function output($data, $label = NULL, $print_r = FALSE) {
+    // Print $data contents to string.
+    $string = String::checkPlain($print_r ? print_r($data, TRUE) : static::varExport($data, TRUE));
+
+    // Display values with pre-formatting to increase readability.
+    $string = '<pre>' . $string . '</pre>';
+
+    trigger_error(trim($label ? "$label: $string" : $string));
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Component/Utility/DebugTest.php b/core/tests/Drupal/Tests/Component/Utility/DebugTest.php
new file mode 100644
index 0000000..ae85ae0
--- /dev/null
+++ b/core/tests/Drupal/Tests/Component/Utility/DebugTest.php
@@ -0,0 +1,62 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Component\Utility\DebugTest.
+ */
+
+namespace Drupal\Tests\Component\Utility;
+
+use Drupal\Component\Utility\Debug;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests the Debug utility.
+ *
+ * @see \use Drupal\Component\Utility\Debug
+ */
+class DebugTest extends UnitTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Debug tests',
+      'description' => 'Tests methods on the Debug utility class.',
+      'group' => 'Common',
+    );
+  }
+
+  /**
+   * Tests String::varExport().
+   *
+   * @dataProvider providerVarExport
+   *
+   * @param $var
+   *   The variable to process.
+   * @param string $expected
+   *   The expected output from the function.
+   * @param string $prefix
+   *   The prefixing string on each new line.
+   */
+  public function testVarExport($var, $expected, $prefix = '') {
+    $result = Debug::varExport($var, $prefix);
+    $this->assertEquals($expected, $result);
+  }
+
+  /**
+   * Data provider for testVarExport.
+   *
+   * @see testVarExport()
+   */
+  public function providerVarExport() {
+    $tests[] = array(NULL, 'NULL');
+    $tests[] = array(NULL, 'NULL', '*');
+    $tests[] = array(array(), 'array()');
+    $tests[] = array(array('Foo'), "array(\n  'Foo',\n)");
+    $tests[] = array(array('Bar'), "array(\n*  'Bar',\n*)", '*');
+    $tests[] = array('Foobar', "'Foobar'");
+    $tests[] = array('Foobar', "'Foobar'", '***');
+
+    return $tests;
+  }
+
+}
