This commit updates the account tracing logic by adding a check for both development and pre-production environments to determine if tracing is enabled. Additionally, it introduces a fallback error logging mechanism to capture log entries when the log file is not writable, improving the robustness of the tracing functionality. These changes aim to enhance debugging capabilities and ensure reliable logging in various environments.
72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Trace diagnostic /compte + login — dev seulement, ?trace_compte=1
|
|
* Écrit dans logs/compte-trace.log (dernier arrêt = dernier step avant freeze/redirect).
|
|
*/
|
|
|
|
function fxTraceCompteEnabled()
|
|
{
|
|
static $blnEnabled = null;
|
|
|
|
if ($blnEnabled !== null) {
|
|
return $blnEnabled;
|
|
}
|
|
|
|
global $vblnEnvironementDev, $vblnEnvironementPreProd;
|
|
|
|
if (empty($vblnEnvironementDev) && empty($vblnEnvironementPreProd)) {
|
|
$blnEnabled = false;
|
|
return false;
|
|
}
|
|
|
|
if (isset($_GET['trace_compte'])) {
|
|
$_SESSION['trace_compte'] = ($_GET['trace_compte'] === '1' || $_GET['trace_compte'] === 'on');
|
|
}
|
|
|
|
$blnEnabled = !empty($_SESSION['trace_compte']);
|
|
|
|
return $blnEnabled;
|
|
}
|
|
|
|
function fxTraceCompte($strStep, $arrExtra = array())
|
|
{
|
|
if (!fxTraceCompteEnabled()) {
|
|
return;
|
|
}
|
|
|
|
$arrCtx = array(
|
|
't' => microtime(true),
|
|
'step' => $strStep,
|
|
'uri' => $_SERVER['REQUEST_URI'] ?? '',
|
|
'method' => $_SERVER['REQUEST_METHOD'] ?? '',
|
|
'com_id' => $_SESSION['com_id'] ?? null,
|
|
'usa_id' => $_SESSION['usa_id'] ?? null,
|
|
'redirect_after_login' => $_SESSION['redirect_after_login'] ?? null,
|
|
);
|
|
|
|
if (!empty($arrExtra)) {
|
|
$arrCtx = array_merge($arrCtx, $arrExtra);
|
|
}
|
|
|
|
$strLine = date('Y-m-d H:i:s') . ' ' . json_encode($arrCtx, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n";
|
|
|
|
$strDir = dirname(__DIR__) . '/logs';
|
|
if (!is_dir($strDir)) {
|
|
@mkdir($strDir, 0755, true);
|
|
}
|
|
|
|
@file_put_contents($strDir . '/compte-trace.log', $strLine, FILE_APPEND | LOCK_EX);
|
|
|
|
// Secours si le dossier logs n'est pas inscriptible (permissions serveur).
|
|
if (!is_file($strDir . '/compte-trace.log')) {
|
|
@error_log('compte-trace: ' . trim($strLine));
|
|
}
|
|
}
|
|
|
|
/** Appeler juste avant header('Location:…'); exit; */
|
|
function fxTraceCompteRedirect($strStep, $strUrl)
|
|
{
|
|
fxTraceCompte($strStep, array('redirect_to' => $strUrl));
|
|
}
|