|
目录
来源:http://trac.seagullproject.org/wiki/Integration/FirePHP FirePHP集成FirePHP (http://www.firephp.org/ 和 http://www.firephp.org/HQ/Use.htm) 让你可以通过调用PHP方法输出内容到Firebug控制台。所有的数据是通过响应header发送的不能和页面的内容发生关系。FirePHP是AJAX开发的理想工具,尤其适用于ajax要求返回的JSON或XML响应格式。 1. 获取FirePHP核心库[[http://www.firephp.org/DownloadRelease/FirePHPLibrary-FirePHPCore-0.2.1]]
2. 复制FirePHPCore-0.2.1/lib/到{seagull}/lib/other如下:
lib/other/FirePHPCore with fb.php, FirePHP.class.php, and LICENSE 封装类目前FirePHP类没有任何修改或自定义。不过下面的这样封装类可以在需要的时候做一些必要的修改或自定义。 require_once 'other/FirePHPCore/FirePHP.class.php'; class SGL_FirePhp extends FirePHP
{
}
default/classes/ConfigMgr.php添加一个新的日志类型'firephp' $this->aLogTypes = array(
'file' => 'file',
'mcal' => 'mcal',
'sql' => 'sql',
'syslog' => 'syslog',
'firephp' => 'firephp',
);
集成关键步骤SGL::logMessages()如果log已经被设置成'firephp' 那么 … if (!empty($conf['log']['type']) && $conf['log']['type'] == 'firephp' && version_compare(phpversion(), '5.0.0') >= 0) {
require_once SGL_CORE_DIR . '/FirePhp.php';
$logger = SGL_FirePhp::getInstance(true);
// Disable logging for live sites
if(!empty($conf['debug']['production']) && $conf['debug']['production']) {
$logger->setEnabled(false);
}
} else {
include_once 'Log.php';
// Instantiate a logger object based on logging options
$logger = & Log::singleton($conf['log']['type'],
$logName,
$conf['log']['ident'],
array( $conf['log']['paramsUsername'],
$conf['log']['paramsPassword'],
'dsn' => $dsn
));
}
ErrorHandler?如果已经启用了FirePHP,那么使用CLI错误输出格式并输出错误信息到FireBugFireBug控制台 if (SGL::runningFromCLI() ||
(!empty($conf['log']['type']) &&
$conf['log']['type'] == 'firephp' &&
version_compare(phpversion(), '5.0.0') >= 0)) {
$output = <<<EOL
MESSAGE: $errStr
TYPE: {$this->errorType[$errNo][0]}
FILE: $file
LINE: $line
EOL; } if (!empty($conf['log']['showErrors']) && $conf['log']['showErrors'] == true) { if (!empty($conf['log']['type']) &&
$conf['log']['type'] == 'firephp' &&
version_compare(phpversion(), '5.0.0') >= 0) {
require_once SGL_CORE_DIR . '/FirePhp.php';
$logger = SGL_FirePhp::getInstance(true);
$logger->log($output);
} else {
echo $output;
}
}
ManagerFirePHP还可用来调试。不使用echo而提供一个快捷的方式来输出变量的值等。FirePHP 可以输出这些些到控制台。 require_once SGL_CORE_DIR . '/FirePhp.php'; In the Managers constructor add something like this $this->firePhp = SGL_FirePhp::getInstance(true); // Disable logging for live sites
if($this->conf['debug']['production']) {
$this->firePhp->setEnabled(false);
}
然后在the _cmd_foo()方法 $this->firePhp->log('The value of foo is: ' . $foo);
Settings to enable FirePHP logging:debug - production = false debug - show errors = true log - type = firephp log - enabled = true Diff Files, EtcTicket URL: http://trac.seagullproject.org/ticket/1697 |