<?php function mylog($word = '',$var=array(), $log_name='Log', $log_path=ROOT_PATH."data/log/") { $output = "----------------------------------------------------------------------------------------------------\n"; $output .= strftime("%Y%m%d %H:%M:%S", time()) . " " ; $output .= $word."\n" ; if(!empty($var)){ $output .= print_r($var, true)."\n"; } $output.="\n"; if(!is_dir($log_path)){ @mkdir($log_path, 0777, true); } file_put_contents($log_path . $log_name . "_".strftime("%Y%m%d", time()).".txt", $output, FILE_APPEND | LOCK_EX); } ?>
在项目中引入mylog.php, 即可使用。使用方式:
echolog(数据源,'文件名','文件路径');
如有不足之处, 欢迎留言指导