Tp5自定义路径写入日志

Log::init(['type'=>'类型', 'path'=>'自定义路径']);

Log::write('日志内容');

/**
* [ tp自带写入日志 -详细]
* @param array,string $log_content [内容]
* @param string     $keyp [文件名]
* @return [type]       [description]
*/
function tp_log($log_content,$keyp){
hinkLog::init(['type' => 'File', 'path' =>ROOT_PATH .'logs'. DS.$keyp.DS]);
hinkLog::write($log_content);
}

//自己写的简约写入日志

/**
* [ 写入日志 -简约]
* @param array,string $log_content [内容]
* @param string $keyp [文件名]
* @return [type]        [description]
*/
function pr_log($log_content, $keyp) {
$log_filename = ROOT_PATH .'logs'.DS .$keyp.DS.date("Ym").DS;
!is_dir($log_filename) && mkdir($log_filename, 0755, true);

if(is_array($log_content)){
$log_content = JSONReturn($log_content);
}
file_put_contents($log_filename.date("d").'.log', '['.date("Y-m-d H:i:s").']' .PHP_EOL . $log_content . PHP_EOL."------------------------ --------------------------".PHP_EOL, FILE_APPEND);
}
function JSONReturn($result)
{
return json_encode($result,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}


//放入公共方法方便调用
pr_log(['博客园'=>'第一篇随笔'],'测试');
tp_log(博客园,'测试');
原文地址:https://www.cnblogs.com/liuzheyan/p/11130552.html