diff --git a/includes/errors.inc b/includes/errors.inc
index 7393148..886c465 100644
--- a/includes/errors.inc
+++ b/includes/errors.inc
@@ -62,8 +62,7 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c
       require_once DRUPAL_ROOT . '/includes/common.inc';
     }
 
-    // We treat recoverable errors as fatal.
-    _drupal_log_error(array(
+    $error_details = array(
       '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error',
       // The standard PHP error handler considers that the error messages
       // are HTML. We mimick this behavior here.
@@ -72,7 +71,16 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c
       '%file' => $caller['file'],
       '%line' => $caller['line'],
       'severity_level' => $severity_level,
-    ), $error_level == E_RECOVERABLE_ERROR);
+    );
+    // If 'drupal_error_log_backtrace' is set. It will display backtrace on top
+    // of actual error message.
+    if (variable_get('drupal_error_log_backtrace', TRUE)) {
+      $exception = new Exception();
+      $error_details['@backtrace_string'] = $exception->getTraceAsString();
+    }
+
+    // We treat recoverable errors as fatal.
+    _drupal_log_error($error_details, $error_level == E_RECOVERABLE_ERROR);
   }
 }
 
@@ -111,7 +119,7 @@ function _drupal_decode_exception($exception) {
   }
   $caller = _drupal_get_last_caller($backtrace);
 
-  return array(
+  $error_details = array(
     '%type' => get_class($exception),
     // The standard PHP exception handler considers that the exception message
     // is plain-text. We mimick this behavior here.
@@ -121,6 +129,13 @@ function _drupal_decode_exception($exception) {
     '%line' => $caller['line'],
     'severity_level' => WATCHDOG_ERROR,
   );
+
+  if (variable_get('drupal_error_log_backtrace', TRUE)) {
+    $exception = new Exception();
+    $error_details['@backtrace_string'] = $exception->getTraceAsString();
+  }
+
+  return $error_details;
 }
 
 /**
@@ -255,6 +270,13 @@ function _drupal_log_error($error, $fatal = FALSE) {
       exit;
     }
   }
+
+  if (array_key_exists('@backtrace_string', $error)) {
+    error_log(sprintf('%s: %s in %s on line %d %s', $error['%type'], $error['!message'], $error['%file'], $error['%line'], $error['@backtrace_string']));
+  }
+  else {
+    error_log(sprintf('%s: %s in %s on line %d', $error['%type'], $error['!message'], $error['%file'], $error['%line']));
+  }
 }
 
 /**
