PHP Create log record (encapsulated)

Source: Internet
Author: User

1<?PHP2 3 classlogs{4     Private $_filepath;//file path5     Private $_filename;//file name6     Private $_filehandle;//file Engine7 8 9       Public functionLogs ($dir=NULL,$filename=NULL){Ten       One      $this->_filepath =Empty($dir) ? ‘‘:$dir; A      $this->_filename =Empty($filename) ?Date(' y-m-d ', Time()).‘. Log ':$filename; -      -     //Create Path the      $path=$this->_createpath ($this->_filepath,$this-_filename); -  -      if(!$this->_isexist ($path)){//If the log directory does not exist -  +         if(!Empty($this->_filepath)) {//if the path does not exist -   +           if(!$this->_createdir ($this->_filepath)) {//Create Path A             die("Create log directory not successful"); at           } -         } -  -         if(!$this->_createlogfile ($path)){//Create a log -           die("Create log file is unsuccessful"); -         } in      } -      to  +      $path=$this->_createpath ($this->_filepath,$this-_filename); -      //Create a log file the      $this->_filehandle=fopen($path, "A +"); *      } $     Panax Notoginseng      -       Public functionSetlog ($log)//Write Log the     { +          //Write Log A          $str= ""; the          if(Is_array($log)){ +             foreach($log  as $k=$v){ -                $str.=$k." : ".$v." \ n "; $             } $}Else{ -             $str=$log." \ n "; -          } the          -         Wuyi         if(!fwrite($this->_filehandle,$str)){//Write Log the              die("Write Log Error"); -         } Wu      } -      About      $      Private function_isexist ($path){ -      return file_exists($path); -      } -      A      +      Private function_createdir ($dir){    the          return Is_dir($dir) or ($this->_createdir (dirname($dir)) andmkdir($dir, 0777)); -      } $      the      the      Private function_createlogfile ($path){    the          $handle=fopen($path, "W");// the          fclose($handle); -          return $this->_isexist ($path); in      } the      the      About      Private function_createpath ($dir,$filename){ the         if(Empty($dir)){ the         return $filename; the}Else{ +         return $dir." /".$filename; -         } the      }Bayi      the      the      function__destruct () { -      //Close Log -      fclose($this-_filehandle); the      } the  } the?>

PHP Create log record (encapsulated)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.