作者:蔡少暖_171 | 来源:互联网 | 2023-10-12 13:54
// 全局通用日志工具
function setlog($param = [],$result = [],$name='',$filename = '',$path = ''){
if (!$path) {
$path = BASE_PATH.'../logs/';
}
if (!$filename) {
$filename = 'project.log';
} else {
$filename = $filename;
}
// 没有目录则创建目录
if (!mkdir($path, 0777, true) && !is_dir($path)) {
throw new \RuntimeException(sprintf('目录 "%s" 创建失败', $path));
} // 目录,权限,递归
$arr = array(
'm' => MODULE_NAME,
'c' => CONTROLLER_NAME,
'a' => ACTION_NAME,
'param' => $param,
'result' => $result,
'name' => $name,
'time' => date('Y-m-d H:i:s')
);
file_put_contents($path.$filename,var_export(json_encode($arr,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES),true).PHP_EOL,FILE_APPEND);
file_put_contents($path.$filename,'================> '.date('Y-m-d H:i:s').' end <================'.PHP_EOL,FILE_APPEND);
}