Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error log improvements: Provide priority level #14995

Merged
merged 1 commit into from
Aug 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions CRM/Core/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,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);
CRM_Core_Error::debug_var('Fatal Error Details', $error, TRUE, TRUE, '', PEAR_LOG_ERR);
CRM_Core_Error::backtrace('backTrace', TRUE);

if ($config->initialized) {
Expand Down Expand Up @@ -339,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);
CRM_Core_Error::debug_var('Fatal Error Details', $vars, TRUE, TRUE, '', PEAR_LOG_ERR);
CRM_Core_Error::backtrace('backTrace', TRUE);

$details = 'A fatal error was triggered';
Expand Down Expand Up @@ -381,7 +381,7 @@ function_exists($config->fatalErrorHandler)
self::backtrace();
}

CRM_Core_Error::debug_var('Fatal Error Details', $vars);
CRM_Core_Error::debug_var('Fatal Error Details', $vars, TRUE, TRUE, '', PEAR_LOG_ERR);
CRM_Core_Error::backtrace('backTrace', TRUE);

// If we are in an ajax callback, format output appropriately
Expand Down Expand Up @@ -421,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));
CRM_Core_Error::debug_var('handleUnhandledException_nestedException', self::formatTextException($other), TRUE, TRUE, '', PEAR_LOG_ERR);
}
$config = CRM_Core_Config::singleton();
$vars = [
Expand Down Expand Up @@ -459,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);
CRM_Core_Error::debug_var('Fatal Error Details', $vars, FALSE, TRUE, '', PEAR_LOG_ERR);
CRM_Core_Error::backtrace('backTrace', TRUE);

// print to screen
Expand Down Expand Up @@ -544,14 +544,16 @@ public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE,
* Log or return the output?
* @param string $prefix
* Prefix for output logfile.
* @param int $priority
* The log priority 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 = '') {
public static function debug_var($variable_name, $variable, $print = TRUE, $log = TRUE, $prefix = '', $priority = NULL) {
// check if variable is set
if (!isset($variable)) {
$out = "\$$variable_name is not set";
Expand All @@ -574,7 +576,7 @@ public static function debug_var($variable_name, $variable, $print = TRUE, $log
reset($variable);
}
}
return self::debug_log_message($out, FALSE, $prefix);
return self::debug_log_message($out, FALSE, $prefix, $priority);
}

/**
Expand Down Expand Up @@ -635,7 +637,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');
CRM_Core_Error::debug_var('Query', $string, TRUE, TRUE, 'sql_log', PEAR_LOG_DEBUG);
}
}
}
Expand All @@ -647,7 +649,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]);
CRM_Core_Error::debug_var('dao result', ['query' => $query, 'results' => $results], TRUE, TRUE, '', PEAR_LOG_DEBUG);
}

/**
Expand Down Expand Up @@ -731,7 +733,7 @@ public static function backtrace($msg = 'backTrace', $log = FALSE) {
CRM_Core_Error::debug($msg, $message);
}
else {
CRM_Core_Error::debug_var($msg, $message);
CRM_Core_Error::debug_var($msg, $message, TRUE, TRUE, '', PEAR_LOG_DEBUG);
}
}

Expand Down Expand Up @@ -948,7 +950,7 @@ public static function reset() {
* @throws PEAR_Exception
*/
public static function exceptionHandler($pearError) {
CRM_Core_Error::debug_var('Fatal Error Details', self::getErrorDetails($pearError));
CRM_Core_Error::debug_var('Fatal Error Details', self::getErrorDetails($pearError), TRUE, TRUE, '', PEAR_LOG_ERR);
CRM_Core_Error::backtrace('backTrace', TRUE);
throw new PEAR_Exception($pearError->getMessage(), $pearError);
}
Expand All @@ -962,7 +964,7 @@ public static function exceptionHandler($pearError) {
* $obj
*/
public static function nullHandler($obj) {
CRM_Core_Error::debug_log_message("Ignoring exception thrown by nullHandler: {$obj->code}, {$obj->message}");
CRM_Core_Error::debug_log_message("Ignoring exception thrown by nullHandler: {$obj->code}, {$obj->message}", FALSE, '', PEAR_LOG_ERR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been inconclusively bike-shedding on whether this should be PEAR_LOG_DEBUG or PEAR_LOG_ERR, but I don't think it matters much, so I'm good unless anyone has a strong opinion on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These definitely may be legitimate errors that administrators may need to take action to correct.

If there is truly debug-level info being sent to the nullhandler, then some logic to sort that out from the errors could be a nice further improvement.

CRM_Core_Error::backtrace('backTrace', TRUE);
return $obj;
}
Expand Down