init
This commit is contained in:
30
auth/logger.php
Normal file
30
auth/logger.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user