/** * Logs data to the shibboleth debug log * * @param string $msg the message to log * @param string|object $data additional data to log * @return void **/ private static function log($msg, $data = '') { static $params; if (!isset($params)) { $params = Plugin::params('authentication', 'shibboleth'); } if ($params->get('debug_enabled', true)) { if (!\Log::has('shib')) { $location = $params->get('debug_location', '/var/log/apache2/php/shibboleth.log'); $location = explode(DS, $location); $file = array_pop($location); \Log::register('shib', ['path' => implode(DS, $location), 'file' => $file, 'level' => 'info', 'format' => "%datetime% %message%\n"]); } // Create a token to identify related log entries if (!($cookie = Cookie::eat('shib-dbg-token'))) { $token = base64_encode(uniqid()); Cookie::bake('shib-dbg-token', time() + 60 * 60 * 24, ['shib-dbg-token' => $token]); } else { $token = $cookie->{'shib-dbg-token'}; } $toBeLogged = "{$token} - {$msg}"; if (!empty($data)) { $toBeLogged .= ":\t" . (is_string($data) ? $data : json_encode($data)); } \Log::logger('shib')->info("{$toBeLogged}"); } }