打印日志类

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class  WriteLog{
    
    public static function setLog($file,$content){
        
        $flag = "testwin";
        
        try{
            $file = preg_replace('#[^A-z0-9]#','',$file);
            $_ospath = "C:/S0519LOG/";
            $_ospath2 = "/usr/S0519LOG/";
            $Agent=$_SERVER['HTTP_USER_AGENT'];
           
           if ($flag=="testwin"){
             
                if (!is_dir($_ospath)) mkdir($_ospath); // 如果不存在则创建
                if(!is_dir($_ospath.date('Ymd')))mkdir($_ospath.date('Ymd')); // 如果不存在则创建
                $file = $_ospath.date('Ymd')."/".$file.".txt";
                if (!file_exists($file)) { // 如果不存在则创建

                }
                 
                 $handle=fopen($file,"a");
                 fwrite($handle,"\r\n===".date("h:i:sa")."===\r\n");
                 fwrite($handle,$content);
                 fclose($handle);
            }else if($flag=="testlinux"){
                if(!is_dir($_ospath2.date('Ymd'))){// 如果不存在则创建
                   if(mkdir($_ospath2.date('Ymd')."/", 0777)){

                   }else{

                   }
                }
                $file = $_ospath2.date('Ymd')."/".$file.".txt";
               // echo $file;
                $handle=fopen($file,"a");

                fwrite($handle,"\r\n===".date("h:i:sa")."===\r\n");
                fwrite($handle,$content);

                fclose($handle);

                
            }
           

          
        }catch(Exception $e){
            
        }
        
    }
}
?>

 

posted @ 2015-06-24 13:45  芭菲雨  阅读(261)  评论(0编辑  收藏  举报