zoukankan      html  css  js  c++  java
  • 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;?>	".str_replace(array('<?', '?>'), '', $tmp)."
    ");
                }
                fclose($fp);
            }
        }

    dz的写日志函数,重用性还可以。

  • 相关阅读:
    MYCAT介绍
    MES生产日报存储过程
    HttpContext讲解
    负载均衡session共享问题
    UML学习(二)-----类图
    Hadoop实战第一篇
    网站速度优化的一般方法
    MVC中的ActionResult
    CCF201403-2 窗口(100分)
    CCF201403-2 窗口(100分)
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4980827.html
Copyright © 2011-2022 走看看