分享乙個PHP除錯日誌類

2022-02-24 08:28:14 字數 1492 閱讀 2745

分享乙個我自己用的在 wordpress 開發中用得到的乙個除錯日誌類。

<?php

/** * @author: suifengtec coolwp.com

* @date: 2013-02-03 09:55:55

* @last modified by: suifengtec coolwp.com

* @last modified time: 2015-07-12 18:40:02

*/if(function_exists('add_action'))

if(!class_exists('coolwp_com_log'))

public function __wakeup()

public function __construct($main_file='')

/*** adding log item

* @param string $text : adding content

*/public function add($text)

$fp = fopen( $this->f_path,"a");

flock($fp, lock_ex) ;

fwrite($fp,"".date("y-m-d h:i:s",time())."\n".$text."\n\n");

flock($fp, lock_un);

fclose($fp);

//return true;//}

/*** checking the log file and path.

* @return null

*/private function check_log_file()

if(!$is_file)}}

}/*//class*/

}/*all done.*/

?>

以wordpress外掛程式為例的用例:

在外掛程式主檔案的適當位置加入(假如上述**放置在class-coolwp-debug-log.php檔案中):

$this->is_debug = true;

if($this->is_debug)

如果在外掛程式主檔案中將__file__定義為常量 someone_this,那麼,可以將someone_this 作為引數傳給coolwp_com_log(),例如:

$this->log = new coolwp_com_log(someone_this);

傳不傳引數的區別是日誌檔案的位置不同,如果不傳引數,日誌檔案位於class-coolwp-debug-log.php所在目錄下的debug目錄下;如果傳遞了someone_this引數,那麼,日誌檔案位於外掛程式主目錄下的debug目錄下。日誌檔案的檔名稱為debug_*******log。

日誌條目預設採用北京時間。

在 wordpress 環境中,可以使用 filter hook:

來修改預設的日誌檔案的名稱。

首發 **到。

分享乙個Redis幫助類

在專案中用到了redis的hash集合,但是servicestack封裝的使用起來不方便,於是就自己封裝了乙個dll,利用的servicestack的pool來動態建立iredisclient例項,建立了乙個抽象類redisoperatorbase封裝了一些基本方法。比較簡單,相信大家一看 就會。下...

乙個漂亮的php驗證碼類 分享

下面小灰灰就為大家分享乙個漂亮的php驗證碼類。需要的朋友可以過來參考下。效果圖 直接上 驗證碼類 class validatecode 生成隨機碼 private function createcode 生成背景 private function createbg 生成文字 private fun...

分享乙個php檔案操作工具類

來自帝國cms 蘇作家具 管理系統ftp define inempirecmsftp true class empirecmsftp 鏈結 function fconnect ftphost,ftpport,ftpusername,ftppassword,ftppath,ftpssl 0,pasv ...