在需使用日志页面引入TP_LOG第三方扩展 Vendor(‘utils.Log’); 使用方法 public function logins(){ $request = ‘2222’; \Log::outLog(“网银通知接口”, $request,’epay’);}
\Log::outLog($title, $content, $file_name);
$title 存储日志头部名称$content 存储内容$file_name log日志文件名称 第三方类库代码 LOG.PHP require_once ‘Tools.php’; class Log{ static function outLog($api_n,$content,$type){ $time=Tools::getTime(“Y年m月d日G时i分s秒x毫秒”); $log_str=”$time $api_n\n$content\n——————\n”; $file_n=”Log__”.date(“Ymd”).”.txt”; $path = realpath(__ROOT__).”/Runtime/Logs/”.$type; if (! file_exists ( $path )) { mkdir ( “$path”, 0777, true ); } $file=fopen($path.”/$file_n”, “a+”); fwrite($file, $log_str); fclose($file); } } TOOLS.PHP class Tools{ public static function getTime($tag){ list($usec,$sec)=explode(” “, microtime()); $now_time=((float)$usec+(float)$sec); list($usec,$sec)=explode(“.”, $now_time); $date=date($tag,$usec); return str_replace(‘x’, $sec, $date); } }