php 写日志

 1 <?php
 2 class writelog {
 3 /**
 4 * 写文件
 5 * @param    string  $file   文件路径
 6 * @param    string  $str    写入内容
 7 * @param    char    $mode   写入模式
 8 *
 9 */      
10 //    function writeFile($file,$str,$mode) 
11     function writeFile($debug,$str)
12     {
13         if($debug  = 1)
14       { 
15           $oldmask = @umask(0); 
16           $RootPath = $_SERVER['DOCUMENT_ROOT'].""; 
17         $file = $RootPath.'/log/'.date('Y-m-d').'.log';  
18         $str = date('m-d-s')."       " .$str."

";
19         if(!file_exists($file))
20         {
21                $mode='w';
22         } 
23         else
24         {
25               $mode='a';
26         }                                                       
27       $fp = @fopen($file,$mode);
28       @fwrite($fp,$str);
29       @fclose($fp);
30       @umask($oldmask);
31     }
32   }
33 } 
34 
35 ?>
调用

<?php
  require_once('./lib/writelog.php'); 
  $writelog=new writelog();
  $writelog(1,"aaa");
?>

  

原文地址:https://www.cnblogs.com/mdevi/p/3676878.html