discuz函数解析--写日志
public static function writelog($file, $log) { global $_G; $yearmonth = dgmdate(TIMESTAMP, 'Ym', $_G['setting']['timeoffset']); $logdir = DISCUZ_ROOT.'./data/log/'; $logfile = $logdir.$yearmonth.'_'.$file.'.php'; if(@filesize($logfile) > 2048000) { //判断文件大小,如果超过2M,则将日志文件重命名 $dir = opendir($logdir); $length = strlen($file); $maxid = $id = 0; while($entry = readdir($dir)) { if(strpos($entry, $yearmonth.'_'.$file) !== false) { $id = intval(substr($entry, $length + 8, -4)); $id > $maxid && $maxid = $id; } } closedir($dir); $logfilebak = $logdir.$yearmonth.'_'.$file.'_'.($maxid + 1).'.php'; @rename($logfile, $logfilebak); } if($fp = @fopen($logfile, 'a')) { @flock($fp, 2);//文件锁 if(!is_array($log)) { $log = array($log); } foreach($log as $tmp) { fwrite($fp, "<?PHP exit;?>\t".str_replace(array('<?', '?>'), '', $tmp)."\n"); } fclose($fp); } }
dz的写日志函数,重用性还可以。
posted on 2015-11-20 15:09 liuwenbohhh 阅读(461) 评论(0) 编辑 收藏 举报