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

Move debug backtrace of auth_oidc error details from Moodle log to PHP error log #2749

Open
wants to merge 1 commit into
base: MOODLE_403_STABLE
Choose a base branch
from
Open
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
43 changes: 39 additions & 4 deletions auth/oidc/classes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,53 @@ public static function tostring($val) {
public static function debug($message, $where = '', $debugdata = null) {
$debugmode = (bool)get_config('auth_oidc', 'debugmode');
if ($debugmode === true) {
$backtrace = debug_backtrace();
$otherdata = [
$debugbacktrace = debug_backtrace();
$debugbacktracechecksum = md5(json_encode($debugbacktrace));

$otherdata = static::make_json_safe([
'other' => [
'message' => $message,
'where' => $where,
'debugdata' => $debugdata,
'backtrace' => $backtrace,
'backtrace_checksum' => $debugbacktracechecksum,
],
];
]);
$event = action_failed::create($otherdata);
$event->trigger();

$debugbacktracedata = [
'checksum' => $debugbacktracechecksum,
'backtrace' => $debugbacktrace,
];

debugging(json_encode($debugbacktracedata), DEBUG_DEVELOPER);
}
}

/**
* Make a JSON structure safe for logging.
*
* @param mixed $data The data to make safe.
* @return mixed The safe data.
*/
private static function make_json_safe($data) {
if (is_array($data)) {
foreach ($data as $key => $value) {
$data[$key] = static::make_json_safe($value);
}
} else if (is_object($data)) {
$data = (array)$data;
foreach ($data as $key => $value) {
$data[$key] = static::make_json_safe($value);
}
} else if (is_bool($data)) {
$data = (int)$data;
} else if (is_null($data)) {
$data = null;
} else if (!is_scalar($data)) {
$data = (string)$data;
}
return $data;
}

/**
Expand Down
Loading