日志方法可以写到公共类。
1 2 3 4 5 6 7 8 | public function test(){ /* * __METHOD__ * 获取当前方法名 */ $aa=array("name"=>"joan","num"=>"9018","email"=>"abc@abc.com"); $this->setLog(__METHOD__,$aa); } |
简单易懂。为自己简便,懒人
1 2 3 4 5 6 7 8 9 10 11 12 13 | public function setLog($mothod,$log){ $date = date("Y-m-d",time());//时间定义文件名 $get_keys = array_keys($log);//获取数组下标。 $file = $date.'log.txt';//定义日志文件名 for($i = 0; $i<count($log); $i++){ if($i == 0){ $yx_content = "-----".$mothod."()\r\n"; file_put_contents($file, $yx_content,FILE_APPEND); } $yx_content = $get_keys[$i].":".$log[$get_keys[$i]].",\r\n"; file_put_contents($file, $yx_content,FILE_APPEND); } } |