#17605348 * debugPrint()에 FirePHP 연동 추가

* PHP 5.2 이상에서 작동. 만족하지 못하면 _debug_message.php 파일에 작성됨
  * FirePHP 파이어폭스 플러그인 필요함. https://addons.mozilla.org/en-US/firefox/addon/6149

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@5221 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
bnu 2009-01-05 06:13:09 +00:00
parent 9c4c6d5de5
commit 935d26cf8d
5 changed files with 157 additions and 1428 deletions

View file

@ -145,26 +145,29 @@
$this->elapsed_time = $elapsed_time;
$GLOBALS['__db_elapsed_time__'] += $elapsed_time;
$str = sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time);
$log['query'] = $this->query;
$log['elapsed_time'] = $elapsed_time;
// 에러 발생시 에러 로그를 남김 (__DEBUG_DB_OUTPUT__이 지정되어 있을경우)
if($this->isError()) {
$str .= sprintf("\t Query Failed : %d\n\t\t\t %s\n", $this->errno, $this->errstr);
$log['result'] = 'Failed';
$log['errno'] = $this->errno;
$log['errstr'] = $this->errstr;
if(__DEBUG_DB_OUTPUT__==1) {
if(__DEBUG_DB_OUTPUT__ == 1) {
$debug_file = _XE_PATH_."files/_debug_db_query.php";
$buff = sprintf("%s\n",print_r($str,true));
if($display_line) $buff = "\n====================================\n".$buff."------------------------------------\n";
if($display_line) $buff = "\n<?php\n/*\n====================================\n".$buff."------------------------------------\n*/\n?>\n";
if(@!$fp = fopen($debug_file,"a")) return;
fwrite($fp, $buff);
fclose($fp);
}
} else {
$str .= "\t Query Success\n";
$log['result'] = 'Success';
}
$GLOBALS['__db_queries__'] .= $str;
$GLOBALS['__db_queries__'][] = $log;
// __LOG_SLOW_QUERY__ 가 정해져 있다면 시간 체크후 쿼리 로그 남김
if(__LOG_SLOW_QUERY__>0 && $elapsed_time > __LOG_SLOW_QUERY__) {

View file

@ -172,6 +172,7 @@
$end = getMicroTime();
if(__DEBUG_OUTPUT__ != 2) {
// debug string 작성 시작
$buff = "\n\n** Debug at ".date('Y-m-d H:i:s')." ************************************************************\n";
@ -183,10 +184,18 @@
$buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->getContentSize());
// DB 로그 작성
if(__DEBUG__>1) {
if(__DEBUG__ > 1) {
if($GLOBALS['__db_queries__']) {
$buff .= "\n- DB Queries\n";
$buff .= $GLOBALS['__db_queries__'];
$num = 0;
foreach($GLOBALS['__db_queries__'] as $query) {
$buff .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$num, $query['query'], $query['elapsed_time']);
if($query['result'] == 'Success') {
$buff .= "\t Query Success\n";
} else {
$buff .= sprintf("\t Query $s : %d\n\t\t\t %s\n", $query['result'], $query['errno'], $query['errstr']);
}
}
}
$buff .= "\n- Elapsed time\n";
@ -212,10 +221,67 @@
// 전체 실행 시간 작성
$buff .= sprintf("\tTotal elapsed time \t\t: %0.5f sec", $end-__StartTime__);
}
if(__DEBUG_OUTPUT__==1 && Context::getResponseMethod()=='HTML') return "<!--\r\n".$buff."\r\n-->";
if(__DEBUG_OUTPUT__ == 1 && Context::getResponseMethod() == 'HTML') {
if(__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) {
$buff = '허용되지 않은 IP 입니다. config/config.inc.php 파일의 __DEBUG_PROTECT_IP__ 상수 값을 자신의 IP로 변경하세요.';
}
return "<!--\r\n".$buff."\r\n-->";
}
if(__DEBUG_OUTPUT__==0) debugPrint($buff, false);
// Firebug 콘솔 출력
if(__DEBUG_OUTPUT__ == 2) {
debugPrint(
array('Request / Response info >>> '.Context::getResponseMethod().' / '.$_SERVER['REQUEST_METHOD'],
array(
array('Request URI', 'Request method', 'Response method', 'Response contents size'),
array(
sprintf("%s:%s%s%s%s", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']),
$_SERVER['REQUEST_METHOD'],
Context::getResponseMethod(),
$this->getContentSize().' byte'
)
)
),
FirePHP::TABLE
);
// 기타 로그 작성
if(__DEBUG__ == 3 || __DEBUG__ == 1) {
debugPrint(
array('Elapsed time >>> Total : '.sprintf('%0.5f sec', $end - __StartTime__),
array(array('DB queries', 'class file load', 'Template compile', 'XmlParse compile', 'PHP', 'Widgets', 'Trans widget&editor'),
array(
sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']),
sprintf('%0.5f sec', $GLOBALS['__elapsed_class_load__']),
sprintf('%0.5f sec (%d called)', $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']),
sprintf('%0.5f sec', $GLOBALS['__xmlparse_elapsed__']),
sprintf('%0.5f sec', $end-__StartTime__-$GLOBALS['__template_elapsed__']-$GLOBALS['__xmlparse_elapsed__']-$GLOBALS['__db_elapsed_time__']-$GLOBALS['__elapsed_class_load__']),
sprintf('%0.5f sec', $GLOBALS['__widget_excute_elapsed__']),
sprintf('%0.5f sec', $GLOBALS['__trans_widget_editor_elapsed__'])
)
)
),
FirePHP::TABLE
);
}
// DB 쿼리 로그
if(__DEBUG__ > 1) {
$queries_output = array(array('Query', 'Elapsed time', 'Result'));
foreach($GLOBALS['__db_queries__'] as $query) {
array_push($queries_output, array($query['query'], sprintf('%0.5f', $query['elapsed_time']), $query['result']));
}
debugPrint(
array('DB Queries >>> '.count($GLOBALS['__db_queries__']).' Queries, '.sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']), $queries_output),
FirePHP::TABLE
);
}
}
}
/**

View file

@ -28,10 +28,19 @@
/**
* @brief 디버그 메세지의 출력 장소
* 0 : files/_debug_message.php 연결하여 출력
* 1 : Response Method XML 형식이 아닐 경우 브라우저에 최상단에 주석으로 표시
* 1 : Response Method XML 형식이 아닐 경우 브라우저에 최하단에 주석으로 표시
* 2 : Firebug 콘솔에 출력 (PHP 5.2 이상. firebug / firephp 플러그인 필요)
**/
define('__DEBUG_OUTPUT__', 0);
/**
* @brief FirePHP 콘솔 브라우저 주석 출력 보안
* 0 : 제한 없음 (권장하지 않음)
* 1 : 지정한 IP 주소에만 허용
**/
define('__DEBUG_PROTECT__', 1);
define('__DEBUG_PROTECT_IP__', '127.0.0.1');
/**
* @brief DB 오류 메세지 출력 정의
* 0 : 출력하지 않음
@ -60,6 +69,13 @@
**/
define('_XE_PATH_', str_replace('config/config.inc.php', '', str_replace('\\', '/', __FILE__)));
/**
* @brief Firebug 콘솔 출력 사용시 관련 파일 require
**/
if(__DEBUG_OUTPUT__ == 2 && version_compare(phpversion(), '5.2', '>') == 1) {
require_once _XE_PATH_.'libs/FirePHPCore/FirePHP.class.php';
}
/**
* @brief 간단하게 사용하기 위한 함수 정의한 파일 require
**/

View file

@ -386,18 +386,37 @@
* ./files/_debug_message.php 파일에 $buff 내용을 출력한다.
* tail -f ./files/_debug_message.php 하여 계속 살펴 있다
**/
function debugPrint($buff = null, $display_line = true) {
if(__DEBUG__ != 0 && __DEBUG_OUTPUT__ !== 1) {
$debug_file = _XE_PATH_."files/_debug_message.php";
function debugPrint($buff = null, $display_option = true) {
static $firephp;
$bt = debug_backtrace();
if(is_array($bt)) $first = array_shift($bt);
$buff = sprintf("[%s %s:%d]\n%s\n", date("Y-m-d H:i:s"), array_pop(explode(DIRECTORY_SEPARATOR, $first["file"])), $first["line"], print_r($buff,true));
$file_name = array_pop(explode(DIRECTORY_SEPARATOR, $first['file']));
$line_num = $first['line'];
if($display_line) $buff = "\n====================================\n".$buff."------------------------------------\n";
if(__DEBUG_OUTPUT__ == 0 || (__DEBUG_OUTPUT__ == 2 && version_compare(phpversion(), '5.2', '>') != 1) ) {
$debug_file = _XE_PATH_.'files/_debug_message.php';
$buff = sprintf("[%s %s:%d]\n%s\n", date('Y-m-d H:i:s'), $file_name, $line_num, print_r($buff, true));
if(@!$fp = fopen($debug_file,"a")) return;
if($display_option === true) $buff = "\n====================================\n".$buff."------------------------------------\n";
$buff = "\n<?php\n/*".$buff."*/\n?>\n";
if(@!$fp = fopen($debug_file, 'a')) return;
fwrite($fp, $buff);
fclose($fp);
} elseif(__DEBUG_OUTPUT__ == 2 && version_compare(phpversion(), '5.2', '>') == 1) {
if(!isset($firephp)) $firephp = FirePHP::getInstance(true);
$label = sprintf('%s:%d', $file_name, $line_num);
// FirePHP 옵션
if($display_option === 'TABLE') {
$label = $display_option;
}
if(__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) {
$buff = '허용되지 않은 IP 입니다. config/config.inc.php 파일의 __DEBUG_PROTECT_IP__ 상수 값을 자신의 IP로 변경하세요.';
$label = null;
}
$firephp->fb($buff, $label);
}
}

File diff suppressed because it is too large Load diff