// 全局通用日志工具
function setlog($param = [],$result = [],$name=\'\',$filename = \'\',$path = \'\'){
if (!$path) {
$path = BASE_PATH.\'../../logs/\';
}
if (!$filename) {
// $filename = C(\'DB_NAME\').\'.log\';
$filename = \'project.log\';
}
// 没有目录则创建目录
if (!mkdir($path, 0777, true) && !is_dir($path)) {
throw new \\RuntimeException(sprintf(\'目录 "%s" 创建失败\', $path));
} // 目录,权限,递归
$arr = array(
\'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),true).php_EOL,FILE_APPEND);
file_put_contents($path.$filename,\'================> \'.date(\'Y-m-d H:i:s\').\' end <================\'.PHP_EOL,FILE_APPEND);
}
升级,不转义特殊字符
// 全局通用日志工具
function setlog($param = [],$result = [],$name=\'\',$filename = \'\',$path = \'\'){
if (!$path) {
$path = BASE_PATH.\'../../logs/\';
}
if (!$filename) {
// $filename = C(\'DB_NAME\').\'.log\';
$filename = \'project.log\';
}
// 没有目录则创建目录
if (!mkdir($path, 0777, true) && !is_dir($path)) {
throw new \\RuntimeException(sprintf(\'目录 "%s" 创建失败\', $path));
} // 目录,权限,递归
$arr = array(
\'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);
}
JSON_UNESCAPED_UNICODE 中文不转义
JSON_PRETTY_PRINT 美化输出
JSON_UNESCAPED_SLASHES 特殊字符不转义