日志写入方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010505805/article/details/80708110

 /*
     * @功能写入日志
     * @params $content 内容
     * @return void
     */
    protected function writeLog($content){
        if(!$this->log_file){
            $log_file= APPS_PATH.'/runtime/cli/'.date('YmW').'/logs.log';
        }else{
            $log_file= APPS_PATH.'/runtime/cli/'.date('YmW').'/'.$this->log_file;
        }
        if(!file_exists($log_file)){  //文件夹不存在的话,创建
            $_file=explode('/',$log_file);
            $len=count($_file);
            $_path='';
            foreach ($_file as $k=>$v){
                if($k==($len-1)){
                    break;
                }
                if($k==0){
                    continue;
                }
                $_path.="/{$v}";
                if(!file_exists($_path)){
                    mkdir($_path);
                }
            }
        }
        $f=fopen($log_file,'ab+');
        fwrite($f,date('Y-m-d H:i:s').' :  ');
        fwrite($f,var_export($content,true));
        fwrite($f,PHP_EOL);
        fclose($f);
    }

猜你喜欢

转载自blog.csdn.net/u010505805/article/details/80708110