Civi::log() - Show errors via session status-message (under right conditions)
authorTim Otten <totten@civicrm.org>
Fri, 21 Jul 2023 08:33:27 +0000 (01:33 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 21 Jul 2023 08:43:29 +0000 (01:43 -0700)
1. The priority is 'error' (or something more severe)
2. The site has enabled debug output
3. The page-request message occurs while the session is available

CRM/Core/Error/Log.php

index 964c7ed0ac2cc47bce5ecf71795acf768975a524..59bd871b7fd314f8bab840fb1a399392227c2662 100644 (file)
@@ -59,9 +59,17 @@ class CRM_Core_Error_Log extends \Psr\Log\AbstractLogger {
       if (isset($context['exception'])) {
         $context['exception'] = CRM_Core_Error::formatTextException($context['exception']);
       }
-      $message .= "\n" . print_r($context, 1);
+      $fullContext = "\n" . print_r($context, 1);
+      $seeLog = sprintf(' (<em>%s</em>)', ts('See log for details.'));
+    }
+    else {
+      $fullContext = $seeLog = '';
+    }
+    $pearPriority = $this->map[$level];
+    CRM_Core_Error::debug_log_message($message . $fullContext, FALSE, '', $pearPriority);
+    if ($pearPriority <= PEAR_LOG_ERR && CRM_Core_Config::singleton()->debug && isset($_SESSION['CiviCRM'])) {
+      CRM_Core_Session::setStatus($message . $seeLog, ts('Error'), 'error');
     }
-    CRM_Core_Error::debug_log_message($message, FALSE, '', $this->map[$level]);
   }
 
 }