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."\n\r";
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值