cundeng 发表于 2018-12-18 14:26:22

A PHP log class for debuging

  分享一个我自己用的在 WordPress 开发中用得到的一个调试日志类。
  以 WordPress 插件为例的用例:
在插件主文件的适当位置加入(假如上述代码放置在class-coolwp-debug-log.php文件中):
$this->is_debug = true;
if($this->is_debug){
    require_once( plugin_dir_path(__FILE__).'classes/class-coolwp-debug-log.php');
    $this->Log = new CoolWP_com_Log();
}  如果在插件主文件中将__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。
日志条目默认采用北京时间。



页: [1]
查看完整版本: A PHP log class for debuging