Revert "CRM_Core_Error::debug_var() should have a level arg; CRM_Core_Error methods...
authormark burdett <mfburdett@gmail.com>
Thu, 8 Aug 2019 21:28:13 +0000 (14:28 -0700)
committermark burdett <mfburdett@gmail.com>
Thu, 8 Aug 2019 21:29:02 +0000 (14:29 -0700)
Due to regression https://lab.civicrm.org/dev/core/issues/1174

This reverts commit 3ac984a463d71d796096d5c78c4abd2de0d0a27d.

CRM/Core/Error.php
CRM/Core/Error/Log.php

index 8166498fc6d0fcccd734cd64370cfc6d71085100..16ac8caf4dd8f7b518a6026b4ad7e9cd868ecdf1 100644 (file)
@@ -39,8 +39,6 @@ require_once 'CRM/Core/Exception.php';
 
 require_once 'Log.php';
 
-use Psr\Log\LogLevel;
-
 /**
  * Class CRM_Exception
  */
@@ -234,7 +232,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     $errorDetails = CRM_Core_Error::debug('', $error, FALSE);
     $template->assign_by_ref('errorDetails', $errorDetails);
 
-    CRM_Core_Error::debug_var('Fatal Error Details', $error, TRUE, TRUE, '', LogLevel::ERROR);
+    CRM_Core_Error::debug_var('Fatal Error Details', $error);
     CRM_Core_Error::backtrace('backTrace', TRUE);
 
     if ($config->initialized) {
@@ -341,7 +339,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
 
     if (self::$modeException) {
       // CRM-11043
-      CRM_Core_Error::debug_var('Fatal Error Details', $vars, TRUE, TRUE, '', LogLevel::ERROR);
+      CRM_Core_Error::debug_var('Fatal Error Details', $vars);
       CRM_Core_Error::backtrace('backTrace', TRUE);
 
       $details = 'A fatal error was triggered';
@@ -383,7 +381,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
       self::backtrace();
     }
 
-    CRM_Core_Error::debug_var('Fatal Error Details', $vars, TRUE, TRUE, '', LogLevel::ERROR);
+    CRM_Core_Error::debug_var('Fatal Error Details', $vars);
     CRM_Core_Error::backtrace('backTrace', TRUE);
 
     // If we are in an ajax callback, format output appropriately
@@ -423,7 +421,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     }
     catch (Exception $other) {
       // if the exception-handler generates an exception, then that sucks! oh, well. carry on.
-      CRM_Core_Error::debug_var('handleUnhandledException_nestedException', self::formatTextException($other), TRUE, TRUE, '', LogLevel::ERROR);
+      CRM_Core_Error::debug_var('handleUnhandledException_nestedException', self::formatTextException($other));
     }
     $config = CRM_Core_Config::singleton();
     $vars = [
@@ -461,7 +459,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     // Case C: Default error handler
 
     // log to file
-    CRM_Core_Error::debug_var('Fatal Error Details', $vars, FALSE, TRUE, '', LogLevel::ERROR);
+    CRM_Core_Error::debug_var('Fatal Error Details', $vars, FALSE);
     CRM_Core_Error::backtrace('backTrace', TRUE);
 
     // print to screen
@@ -546,8 +544,6 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *   Log or return the output?
    * @param string $prefix
    *   Prefix for output logfile.
-   * @param string $level
-   *   The PSR-3 log level.
    *
    * @return string
    *   The generated output
@@ -555,7 +551,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @see CRM_Core_Error::debug()
    * @see CRM_Core_Error::debug_log_message()
    */
-  public static function debug_var($variable_name, $variable, $print = TRUE, $log = TRUE, $prefix = '', $level = LogLevel::INFO) {
+  public static function debug_var($variable_name, $variable, $print = TRUE, $log = TRUE, $prefix = '') {
     // check if variable is set
     if (!isset($variable)) {
       $out = "\$$variable_name is not set";
@@ -578,15 +574,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
         reset($variable);
       }
     }
-    Civi::log()->log($level, $out, ['civi.prefix' => $prefix]);
-    return self::debugOutput($out);
-  }
-
-  /**
-   * Generates debug HTML output.
-   */
-  public static function debugOutput($message) {
-    return '<p/><code>' . htmlspecialchars($message) . '</code>';
+    return self::debug_log_message($out, FALSE, $prefix);
   }
 
   /**
@@ -612,7 +600,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     $file_log = self::createDebugLogger($prefix);
     $file_log->log("$message\n", $priority);
 
-    $str = self::debugOutput($message);
+    $str = '<p/><code>' . htmlspecialchars($message) . '</code>';
     if ($out && CRM_Core_Permission::check('view debug output')) {
       echo $str;
     }
@@ -647,7 +635,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
         CRM_Core_Error::backtrace($string, TRUE);
       }
       elseif (CIVICRM_DEBUG_LOG_QUERY) {
-        CRM_Core_Error::debug_var('Query', $string, TRUE, TRUE, 'sql_log', LogLevel::DEBUG);
+        CRM_Core_Error::debug_var('Query', $string, TRUE, TRUE, 'sql_log');
       }
     }
   }
@@ -659,7 +647,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    */
   public static function debug_query_result($query) {
     $results = CRM_Core_DAO::executeQuery($query)->fetchAll();
-    CRM_Core_Error::debug_var('dao result', ['query' => $query, 'results' => $results], TRUE, TRUE, '', LogLevel::DEBUG);
+    CRM_Core_Error::debug_var('dao result', ['query' => $query, 'results' => $results]);
   }
 
   /**
@@ -743,7 +731,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
       CRM_Core_Error::debug($msg, $message);
     }
     else {
-      CRM_Core_Error::debug_var($msg, $message, TRUE, TRUE, '', LogLevel::DEBUG);
+      CRM_Core_Error::debug_var($msg, $message);
     }
   }
 
@@ -960,7 +948,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    * @throws PEAR_Exception
    */
   public static function exceptionHandler($pearError) {
-    CRM_Core_Error::debug_var('Fatal Error Details', self::getErrorDetails($pearError), TRUE, TRUE, '', LogLevel::ERROR);
+    CRM_Core_Error::debug_var('Fatal Error Details', self::getErrorDetails($pearError));
     CRM_Core_Error::backtrace('backTrace', TRUE);
     throw new PEAR_Exception($pearError->getMessage(), $pearError);
   }
@@ -974,7 +962,7 @@ class CRM_Core_Error extends PEAR_ErrorStack {
    *   $obj
    */
   public static function nullHandler($obj) {
-    Civi::log()->error("Ignoring exception thrown by nullHandler: {$obj->code}, {$obj->message}");
+    CRM_Core_Error::debug_log_message("Ignoring exception thrown by nullHandler: {$obj->code}, {$obj->message}");
     CRM_Core_Error::backtrace('backTrace', TRUE);
     return $obj;
   }
index 503a576de60f76319b9a1fd74d7de5b0e5ccf0dd..fc31c16223f8963b474e1f9f50646bcb5cd85198 100644 (file)
@@ -59,7 +59,6 @@ class CRM_Core_Error_Log extends \Psr\Log\AbstractLogger {
   public function log($level, $message, array $context = []) {
     // FIXME: This flattens a $context a bit prematurely. When integrating
     // with external/CMS logs, we should pass through $context.
-    $prefix = '';
     if (!empty($context)) {
       if (isset($context['exception'])) {
         $context['exception'] = CRM_Core_Error::formatTextException($context['exception']);
@@ -69,11 +68,8 @@ class CRM_Core_Error_Log extends \Psr\Log\AbstractLogger {
       if (CRM_Utils_System::isDevelopment() && CRM_Utils_Array::value('civi.tag', $context) === 'deprecated') {
         trigger_error($message, E_USER_DEPRECATED);
       }
-      if (isset($context['civi.prefix'])) {
-        $prefix = $context['civi.prefix'];
-      }
     }
-    CRM_Core_Error::debug_log_message($message, FALSE, $prefix, $this->map[$level]);
+    CRM_Core_Error::debug_log_message($message, FALSE, '', $this->map[$level]);
   }
 
 }