38 lines
1.1 KiB
PHP
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) {
|
|
}
|
|
}
|
|
}
|
|
}
|