Files
web_auth/auth/logger.php
2026-01-19 05:35:37 +03:00

31 lines
603 B
PHP

<?php
function auth_log_event(array $entry): void
{
$config = require __DIR__ . "/config.php";
$dir = $config["logging"]["dir"];
$file = $config["logging"]["file"];
if (!is_dir($dir)) {
@mkdir($dir, 0755, true);
}
$entry["ts"] = $entry["ts"] ?? gmdate("c");
$line = json_encode($entry, JSON_UNESCAPED_UNICODE);
if ($line === false) {
return;
}
$fh = @fopen($file, "ab");
if ($fh === false) {
return;
}
if (flock($fh, LOCK_EX)) {
fwrite($fh, $line . PHP_EOL);
flock($fh, LOCK_UN);
}
fclose($fh);
}