Improve log file support

This commit is contained in:
Benjamin Renard 2021-03-31 12:45:52 +02:00
parent aab9ece941
commit 85580fb6ae
2 changed files with 22 additions and 4 deletions

View file

@ -32,8 +32,17 @@ $cas_servers=array(
// FQDN of CAS server // FQDN of CAS server
$default_cas_server=key($cas_servers); $default_cas_server=key($cas_servers);
// PhpCAS log file // PhpCAS debug logs
$phpCAS_logfile='cas.log';
// Log directory path
$phpCAS_logdir='logs';
// Log filename format
// Compose with :
// - {cas_server} : the CAS server
// - {remote_addr} : connected user remote IP address
// - {session_id} : connected user session_id
$phpCAS_logfile_format='{session_id}-{cas_server}.log';
// Local app URL (auto-detect on first acces if null) // Local app URL (auto-detect on first acces if null)
$service_url=null; $service_url=null;
@ -207,6 +216,13 @@ foreach($cas_servers as $srv => $opts) {
<li><a href='?do=caslogout'>Logout on CAS server</a></li> <li><a href='?do=caslogout'>Logout on CAS server</a></li>
<li><a href='?do=locallogout'>Logout on local application</a></li> <li><a href='?do=locallogout'>Logout on local application</a></li>
<?php <?php
// Generate phpCAS debug log file path
$phpCAS_logfile="$phpCAS_logdir/$phpCAS_logfile_format";
$phpCAS_logfile=str_replace('{cas_server}', $cas_host, $phpCAS_logfile);
$phpCAS_logfile=str_replace('{remote_addr}', $_SERVER['REMOTE_ADDR'], $phpCAS_logfile);
$phpCAS_logfile=str_replace('{session_id}', session_id(), $phpCAS_logfile);
if (is_writable($phpCAS_logfile)) { if (is_writable($phpCAS_logfile)) {
echo "<li><a href='?truncatelog=true'>Truncate Debug log file content</a></li>"; echo "<li><a href='?truncatelog=true'>Truncate Debug log file content</a></li>";
} }
@ -224,8 +240,8 @@ $phpCAS_config=array(
'Service URL' => $service_url, 'Service URL' => $service_url,
); );
if (is_writable($phpCAS_logfile)) { if (is_writable($phpCAS_logfile) || (!is_file($phpCAS_logfile) && is_writable(dirname($phpCAS_logfile)))) {
if (isset($_REQUEST['truncatelog'])) { if (is_file($phpCAS_logfile) && isset($_REQUEST['truncatelog'])) {
$fh = fopen($phpCAS_logfile, 'w'); $fh = fopen($phpCAS_logfile, 'w');
fclose($fh); fclose($fh);
} }

2
logs/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.log
*.log.*