Skip to content

Commit

Permalink
Merge pull request #14997 from civicrm/5.17
Browse files Browse the repository at this point in the history
5.17 to master
  • Loading branch information
eileenmcnaughton authored Aug 8, 2019
2 parents ee9f177 + 9132fee commit be9b544
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
38 changes: 13 additions & 25 deletions CRM/Core/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

require_once 'Log.php';

use Psr\Log\LogLevel;

/**
* Class CRM_Exception
*/
Expand Down Expand Up @@ -234,7 +232,7 @@ public static function handle($pearError) {
$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) {
Expand Down Expand Up @@ -341,7 +339,7 @@ public static function fatal($message = NULL, $code = NULL, $email = NULL) {

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';
Expand Down Expand Up @@ -383,7 +381,7 @@ function_exists($config->fatalErrorHandler)
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
Expand Down Expand Up @@ -423,7 +421,7 @@ public static function handleUnhandledException($exception) {
}
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 = [
Expand Down Expand Up @@ -461,7 +459,7 @@ function_exists($config->fatalErrorHandler)
// 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
Expand Down Expand Up @@ -546,16 +544,14 @@ public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE,
* 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
*
* @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";
Expand All @@ -578,15 +574,7 @@ public static function debug_var($variable_name, $variable, $print = TRUE, $log
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);
}

/**
Expand All @@ -612,7 +600,7 @@ public static function debug_log_message($message, $out = FALSE, $prefix = '', $
$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;
}
Expand Down Expand Up @@ -647,7 +635,7 @@ public static function debug_query($string) {
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');
}
}
}
Expand All @@ -659,7 +647,7 @@ public static function debug_query($string) {
*/
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]);
}

/**
Expand Down Expand Up @@ -743,7 +731,7 @@ public static function backtrace($msg = 'backTrace', $log = FALSE) {
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);
}
}

Expand Down Expand Up @@ -960,7 +948,7 @@ public static function reset() {
* @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);
}
Expand All @@ -974,7 +962,7 @@ public static function exceptionHandler($pearError) {
* $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;
}
Expand Down
6 changes: 1 addition & 5 deletions CRM/Core/Error/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function __construct() {
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']);
Expand All @@ -69,11 +68,8 @@ public function log($level, $message, array $context = []) {
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]);
}

}

0 comments on commit be9b544

Please sign in to comment.