Loginterface.php文件php
1 <?php 2 class Others_Loginterface extends Others_Log 3 { 4 /** 5 *EMERG = 0; // Emergency: 系統不可用 6 ALERT = 1; // Alert: 報警 7 CRIT = 2; // Critical: 緊要 8 ERR = 3; // Error: 錯誤 9 WARN = 4; // Warning: 警告 10 NOTICE = 5; // Notice: 通知 11 INFO = 6; // Informational: 通常信息 12 DEBUG = 7; // Debug: 小時消息 13 * 14 * 15 * @param unknown_type $file 16 * @param unknown_type $msg 17 */ 18 protected static $msg=array(); 19 protected static $body=array(); 20 protected static $file=""; 21 protected static $charset=""; 22 23 /** 24 *開始記錄日誌* 25 * 26 */ 27 public function start($fname="",$charset="") 28 { 29 self::$msg=array(); 30 self::$body=array(); 31 //self::$file=$_SERVER["Root_STATIC"]."/apparel/interface/".date("Ym")."/".date("Ymd")."/".$fname.date("Ymd").".log"; 32 //self::createfile(self::$file); ///不用開創文件 33 self::$file=$fname.date("Ymd").".log"; 34 $tmp[]="\r\n時間:".date("Y-m-d H:i:s").'IP'.$_SERVER['Server_IP']; 35 $tmp[]="====================+++++++++++++++++++開始+++++++++++++++++++================\r\n"; 36 self::$msg[]=implode("\r\n",$tmp); 37 self::$charset=$charset; 38 } 39 40 public static function add($msg) 41 { 42 ///判斷編碼 只有utf-8寫入,非utf-8進行轉碼 43 //if(is_string($msg) && strlen($msg)>0 && self::isGBK($msg)) $msg=iconv("GBK","UTF-8//IGNORE",$msg); 44 if(is_string($msg) && strlen($msg)>0 && self::isGBK($msg)) $msg = mb_convert_encoding($msg,"UTF-8","GBK"); 45 46 if(count(self::$body)==0) self::$body[]="\r\n其它輸出:"; 47 self::$body[]= "\r\n".$msg; 48 } 49 50 public static function end() 51 { 52 self::$msg[]=implode("\r\n",self::$body); 53 self::$msg[]="====================+++++++++++++++++++結束+++++++++++++++++++================\r\n\r\n\r\n"; 54 /*如下進行編碼轉換*/ 55 $msg=implode("\r\n",self::$msg); 56 //var_dump(self::$file); 57 58 ///不是這幾個接口文件,進行編碼轉換,由於這些是gb2312編碼 。之後寫日誌,須要寫入編碼爲:utf8就不會有亂碼 59 /* 60 if(strlen($msg)>0 && !preg_match("/(sailsearch|sailpay|SUAN|HU|MU|CZ|HOTEL)/",self::$file)) ///gb2312 都須要寫入這裏 61 { 62 $msg=iconv("utf-8","gb2312//TRANSLIT",$msg); 63 } 64 */ 65 //if (is_string($msg) && strlen($msg)>0) $msg=iconv("UTF-8","GBK//IGNORE",$msg); ///全部寫入編碼轉爲gbk,由於經過前面操做,全部已是utf-8 66 if (is_string($msg) && strlen($msg)>0) $msg = mb_convert_encoding($msg,"GBK","UTF-8"); 67 68 //self::write(self::$file,$msg,6); 69 Others_Log::write(self::$file,$msg); 70 } 71 72 /***本寫入日誌文件,目前支持utf8與gbk ***/ 73 protected static function isGBK($msg) 74 { 75 return is_string($msg)&&!mb_check_encoding($msg,'utf-8')?true:false; 76 } 77 78 public static function write($file,$data,$info=6) 79 { 80 $posturl = $_SERVER['APP_FILE_URL']; 81 $data=array('file'=>$file,'data'=>$data,'option'=>'append'); 82 Others_Httpclient::quickPost($posturl,$data); 83 } 84 85 86 87 }
Log.php文件web
1 <?php 2 class Others_Log 3 { 4 /** 5 * @param unknown_type $file 6 * @param unknown_type $msg 7 */ 8 public static function write($file,$msg) 9 { 10 $logPath = "/data/web_files/static/apparel/interface/".date("Ym")."/".date("Ymd")."/"; 11 //if(!is_dir($logPath)) mkdir($logPath); 12 self::Directory($logPath); 13 $f = file_put_contents($logPath.$file, $msg,FILE_APPEND) 14 } 15 16 public static function Directory( $dir ){ 17 return is_dir ( $dir ) or self::Directory(dirname( $dir )) and mkdir ( $dir , 0777); 18 } 19 20 21 function createdir($path) 22 { 23 24 $arr=explode('/',dirname($path)); 25 $tmp = Data_Path; 26 foreach ($arr as $a) 27 { 28 $tmp = $tmp.'/'.$a; 29 if(!file_exists($tmp)) mkdir($tmp,0755); 30 } 31 return Data_Path."/".$path; 32 } 33 34 35 }
使用:app
Loginterface::start( 'SetArrVal' );
Loginterface::add( '$params22222222222= ');
Loginterface::end();post