2020-10-15


   ## 记录日志 :日志文件会自动生成到:根目录
   public function log(){
     
       echo(123);
       $this->putLog('123123');
   }
   
   
	public function putLog($content)
	{
     
	    $path    = $this->getLogPath();
	    
	    $content = $this->setCont($content);
	    
	    return file_put_contents($path, $content);
	}
	
	public function getLogPath($fileName=true)
	{
     
	    $path = 'log';
	    
	    if($fileName)
	    {
     
	        $path = $path . '/log.log';
	    }
	    
	    return $path;
	}
	
	public function setCont($content)
	{
     
	    $path = $this->getLogPath(false);
	    
	    $text = "[" . date("Y-m-d H:i:s") . "]" . $this->getSpace() . json_encode($content) . "\n";
	    
	    if(!is_dir($path))
	    {
     
	        mkdir($path, 0777);
	    }
	    else
	    {
     
	        $text = $this->getLog() . $text;
	    }
	    
	    return $text;
	}
	
	public function getLog()
	{
     
	    return file_get_contents($this->getLogPath());
	}
	
	public function getSpace($len=5)
	{
     
	    $space = "";
	    
	    for ($i=0;$i<$len;$i++)
	    {
     
	       $space .= " "; 
	    }
	    
	    return $space;
	}


我的根是public
2020-10-15_第1张图片

你可能感兴趣的:(日志)