Skip to content

Commit

Permalink
Move debug backtrace of auth_oidc error details from Moodle log to PH…
Browse files Browse the repository at this point in the history
…P error log
  • Loading branch information
weilai-irl committed Feb 4, 2025
1 parent d65c9fc commit d5456f2
Showing 1 changed file with 39 additions and 4 deletions.
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,
];

error_log(print_r($debugbacktracedata, true));
}
}

/**
* 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

0 comments on commit d5456f2

Please sign in to comment.