feat: sistema di log rotante 4 livelli (EverLog + LoggingPDO)
- api/logger.php: EverLog static class con 4 livelli (DEBUG/INFO/WARN/ERROR) - Rotazione oraria/giornaliera configurabile via LOG_ROTATE_HOURS - Max file configurabile via LOG_MAX_FILES (default 14) - Request ID unico per tracciare ogni chiamata API - EverLog::query(), aiCall(), aiResponse(), cache(), slowOp(), exception() - Endpoint get_logs per inspection remota (protetto da SETTINGS_TOKEN) - LoggingPDO + LoggingPDOStatement: auto-log di OGNI query SQLite - api/database.php: getDB() restituisce LoggingPDO (drop-in, retrocompat.) - api/index.php: EverLog integrato in ~82 punti - Entry log in ogni funzione API - callGemini/callGeminiWithFallback: timing AI + aiCall/aiResponse - Rate limiter, unknown action, errori globali, DB connect fail Livello default: INFO (query DB a DEBUG, solo se LOG_LEVEL=DEBUG)
This commit is contained in:
+6
-1
@@ -40,8 +40,13 @@ function _ensureDataDir(): void {
|
||||
|
||||
function getDB(): PDO {
|
||||
_ensureDataDir();
|
||||
// logger.php is required by index.php before getDB() is called.
|
||||
// In cron context it may not be loaded yet — guard with class_exists.
|
||||
$useLogging = class_exists('LoggingPDO', false);
|
||||
$isNew = !file_exists(DB_PATH);
|
||||
$db = new PDO('sqlite:' . DB_PATH);
|
||||
$db = $useLogging
|
||||
? new LoggingPDO('sqlite:' . DB_PATH)
|
||||
: new PDO('sqlite:' . DB_PATH);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
$db->exec("PRAGMA journal_mode=WAL");
|
||||
|
||||
Reference in New Issue
Block a user