Files
coruna-lab/app/Helpers.php
T
hashbro 74a67c3900 init
2026-08-08 05:09:01 +08:00

38 lines
1.1 KiB
PHP

<?php
/* C2 / API request file logs — patterned after qrpay create_log */
if (! function_exists('create_log')) {
/**
* Append a line to public/log/{type}/Ymd.log
*
* @param array|string $str
*/
function create_log($str, string $type = 'c2'): void
{
$str = is_array($str) ? json_encode($str, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : (string) $str;
$logPath = public_path('log/'.$type);
if (! is_dir($logPath)) {
$old = umask(0);
mkdir($logPath, 0777, true);
umask($old);
}
$logName = $logPath.'/'.date('Ymd').'.log';
try {
$url = request()->getRequestUri();
} catch (\Throwable) {
$url = $_SERVER['REQUEST_URI'] ?? '';
}
$logStr = date('Y-m-d H:i:s').' '.$url.' '.$str."\r\n\r\n";
$isNew = ! file_exists($logName);
file_put_contents($logName, $logStr, FILE_APPEND);
if ($isNew) {
try {
chmod($logName, 0777);
} catch (\Throwable) {
}
}
}
}