Heim  >  Artikel  >  php教程  >  记录日志,达到文件大小,自动新建文件

记录日志,达到文件大小,自动新建文件

PHP中文网
PHP中文网Original
2016-05-25 16:59:171064Durchsuche

php代码

    function write($message,$level='ERROR',$type=3,$destination='',$extra='') {
    	$LOG_PATH = './';
    	$LOG_FILE_SIZE = 100;
        $now = date('[ c ]');
        $type = $type?$type:3;
        if($type == 3) { // 文件方式记录日志
            if(empty($destination))
                $destination = $LOG_PATH.date('y-m-d').'.log';
            //检测日志文件大小,超过配置大小则备份日志文件重新生成
            if(is_file($destination) && floor($LOG_FILE_SIZE) <= filesize($destination) )
                  rename($destination,dirname($destination).&#39;/&#39;.basename($destination).&#39;-&#39;.time().&#39;.log&#39;);
        }
        error_log("{$now} {$level}: {$message}\r\n", $type,$destination,$extra );
        //clearstatcache();
    }
    write(&#39;dd&#39;);

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn