#17630622 * 디버그 메시지 출력 코드 정리

* __DEBUG__ 상수의 기본 값(0)에서는 어떠한 메시지도 출력하지 않도록 변경
  * __DEBUG__ 상수의 순차적 증가 값을 비트 값으로 변경
  * config/config.inc.php 파일의 설정 값 보다 우선하는 config/config.user.inc.php 를 먼저 읽도록 추가
  * DisplayHandler::_debugOutput()에서 debugPrint()를 사용하지 않도록 변경

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@5339 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
bnu 2009-01-12 15:54:29 +00:00
parent 27431fb123
commit 2f2578e7f8
3 changed files with 196 additions and 162 deletions

View file

@ -172,86 +172,33 @@
$end = getMicroTime();
if(__DEBUG_OUTPUT__ != 2 || (__DEBUG_OUTPUT__ == 2 && !version_compare(PHP_VERSION, '5.2.0', '>'))) {
// debug string 작성 시작
$buff = "\n\n** Debug at ".date('Y-m-d H:i:s')." ************************************************************\n";
// Request/Response 정보 작성
$buff .= "\n- Request/ Response info\n";
$buff .= sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s\n", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']);
$buff .= sprintf("\tRequest method \t\t\t: %s\n", $_SERVER['REQUEST_METHOD']);
$buff .= sprintf("\tResponse method \t\t: %s\n", Context::getResponseMethod());
$buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->getContentSize());
// DB 로그 작성
if(__DEBUG__ > 1) {
if($GLOBALS['__db_queries__']) {
$buff .= "\n- DB Queries\n";
$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";
if($GLOBALS['__db_elapsed_time__']) $buff .= sprintf("\tDB queries elapsed time\t\t: %0.5f sec\n", $GLOBALS['__db_elapsed_time__']);
}
// 기타 로그 작성
if(__DEBUG__==3) {
$buff .= sprintf("\tclass file load elapsed time \t: %0.5f sec\n", $GLOBALS['__elapsed_class_load__']);
$buff .= sprintf("\tTemplate compile elapsed time\t: %0.5f sec (%d called)\n", $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']);
$buff .= sprintf("\tXmlParse compile elapsed time\t: %0.5f sec\n", $GLOBALS['__xmlparse_elapsed__']);
$buff .= sprintf("\tPHP elapsed time \t\t: %0.5f sec\n", $end-__StartTime__-$GLOBALS['__template_elapsed__']-$GLOBALS['__xmlparse_elapsed__']-$GLOBALS['__db_elapsed_time__']-$GLOBALS['__elapsed_class_load__']);
// 위젯 실행 시간 작성
$buff .= sprintf("\n\tWidgets elapsed time \t\t: %0.5f sec", $GLOBALS['__widget_excute_elapsed__']);
// 레이아웃 실행 시간
$buff .= sprintf("\n\tLayout compile elapsed time \t: %0.5f sec", $GLOBALS['__layout_compile_elapsed__']);
// 위젯, 에디터 컴포넌트 치환 시간
$buff .= sprintf("\n\tTrans widget&editor elapsed time: %0.5f sec\n\n", $GLOBALS['__trans_widget_editor_elapsed__']);
}
// 전체 실행 시간 작성
$buff .= sprintf("\tTotal elapsed time \t\t: %0.5f sec", $end-__StartTime__);
}
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 && version_compare(PHP_VERSION, '5.2.0', '>')) {
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'
)
)
),
'TABLE'
);
if(__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '5.2.0', '>=')) {
static $firephp;
if(!isset($firephp)) $firephp = FirePHP::getInstance(true);
// 기타 로그 작성
if(__DEBUG__ == 3 || __DEBUG__ == 1) {
debugPrint(
if(__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) {
$firephp->fb('Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php', 'The IP address is not allowed.');
return;
}
// 전체 실행 시간 출력, Request/Response info 출력
if(__DEBUG__ & 2) {
$firephp->fb(
array('Request / Response info >>> '.$_SERVER['REQUEST_METHOD'].' / '.Context::getResponseMethod(),
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'
)
)
),
'TABLE'
);
$firephp->fb(
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(
@ -269,21 +216,95 @@
);
}
// DB 쿼리 로그
if(__DEBUG__ > 1) {
// DB 쿼리 내역 출력
if(__DEBUG__ & 4) {
$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->fb(
array(
'DB Queries >>> '.count($GLOBALS['__db_queries__']).' Queries, '.sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']),
$queries_output
),
'TABLE'
);
}
// 파일 및 HTML 주석으로 출력
} else {
// debug string 작성 시작
$buff = "** Debug at ".date('Y-m-d H:i:s').str_repeat('*', 60)."\n";
// 전체 실행 시간 출력, Request/Response info 출력
if(__DEBUG__ & 2) {
// Request/Response 정보 작성
$buff .= "\n- Request/ Response info\n";
$buff .= sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s\n", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']);
$buff .= sprintf("\tRequest method \t\t\t: %s\n", $_SERVER['REQUEST_METHOD']);
$buff .= sprintf("\tResponse method \t\t: %s\n", Context::getResponseMethod());
$buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->getContentSize());
// 전체 실행 시간
$buff .= sprintf("\n- Total elapsed time : %0.5f sec\n", $end-__StartTime__);
$buff .= sprintf("\tclass file load elapsed time \t: %0.5f sec\n", $GLOBALS['__elapsed_class_load__']);
$buff .= sprintf("\tTemplate compile elapsed time\t: %0.5f sec (%d called)\n", $GLOBALS['__template_elapsed__'], $GLOBALS['__TemplateHandlerCalled__']);
$buff .= sprintf("\tXmlParse compile elapsed time\t: %0.5f sec\n", $GLOBALS['__xmlparse_elapsed__']);
$buff .= sprintf("\tPHP elapsed time \t\t: %0.5f sec\n", $end-__StartTime__-$GLOBALS['__template_elapsed__']-$GLOBALS['__xmlparse_elapsed__']-$GLOBALS['__db_elapsed_time__']-$GLOBALS['__elapsed_class_load__']);
// 위젯 실행 시간 작성
$buff .= sprintf("\n\tWidgets elapsed time \t\t: %0.5f sec", $GLOBALS['__widget_excute_elapsed__']);
// 레이아웃 실행 시간
$buff .= sprintf("\n\tLayout compile elapsed time \t: %0.5f sec", $GLOBALS['__layout_compile_elapsed__']);
// 위젯, 에디터 컴포넌트 치환 시간
$buff .= sprintf("\n\tTrans widget&editor elapsed time: %0.5f sec\n", $GLOBALS['__trans_widget_editor_elapsed__']);
}
// DB 로그 작성
if(__DEBUG__ & 4) {
if($GLOBALS['__db_queries__']) {
$buff .= sprintf("\n- DB Queries : %d Queries. %0.5f sec\n", count($GLOBALS['__db_queries__']), $GLOBALS['__db_elapsed_time__']);
$num = 0;
foreach($GLOBALS['__db_queries__'] as $query) {
$buff .= sprintf("\t%02d. %s\n\t\t%0.6f sec. ", ++$num, $query['query'], $query['elapsed_time']);
if($query['result'] == 'Success') {
$buff .= "Query Success\n";
} else {
$buff .= sprintf("Query $s : %d\n\t\t\t %s\n", $query['result'], $query['errno'], $query['errstr']);
}
}
}
}
// HTML 주석으로 출력
if(__DEBUG_OUTPUT__ == 1 && Context::getResponseMethod() == 'HTML') {
if(__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) {
$buff = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php';
}
return "<!--\r\n".$buff."\r\n-->";
}
// 파일에 출력
if(__DEBUG_OUTPUT__ == 0) {
$debug_file = _XE_PATH_.'files/_debug_message.php';
$debug_output = sprintf("[%s %s:%d]\n%s\n", date('Y-m-d H:i:s'), $file_name, $line_num, print_r($debug_output, true));
if($display_option === true) $debug_output = str_repeat('=', 40)."\n".$debug_output.str_repeat('-', 40);
$debug_output = "\n<?php\n/*".$debug_output."*/\n?>\n";
if(@!$fp = fopen($debug_file, 'a')) return;
fwrite($fp, $debug_output);
fclose($fp);
}
}
}
/**
* @brief RequestMethod에 맞춰 헤더 출력
***/
@ -330,4 +351,4 @@
header("Pragma: no-cache");
}
}
?>
?>

View file

@ -1,93 +1,102 @@
<?php
@error_reporting(E_ALL ^ E_NOTICE);
/**
* @file config/config.inc.php
* @author zero (zero@nzeo.com)
* @brief 기본적으로 사용하는 class파일의 include 환경 설정을
**/
@error_reporting(E_ALL ^ E_NOTICE);
if(!defined('__ZBXE__')) exit();
/**
* @brief XE의 전체 버전 표기
* 내용은 XE의 버전을 관리자 페이지에 표시하기 위한 용도이며
* config.inc.php의 수정이 없더라도 공식 릴리즈시에 수정되어 함께 배포되어야
* 파일의 수정이 없더라도 공식 릴리즈시에 수정되어 함께 배포되어야
**/
define('__ZBXE_VERSION__', '1.1.4');
/**
* @brief 디버깅 메세지 출력
* 0 : 디버그 메세지를 생성/ 출력하지 않음
* 1 : 전체 실행 시간에 대해서만 메세지 생성/ 출력
* 2 : 1 + DB 쿼리
* 3 : 모든 로그
**/
define('__DEBUG__', 0);
/**
* @brief 디버그 메세지의 출력 장소
* 0 : files/_debug_message.php 연결하여 출력
* 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 : 출력하지 않음
* 1 : files/_debug_db_query.php 연결하여 출력
**/
define('__DEBUG_DB_OUTPUT__', 0);
/**
* @brief DB 쿼리중 정해진 시간을 넘기는 쿼리의 로그 남김
* 0 : 로그를 남기지 않음
* 0 이상 : 단위를 초로 하여 지정된 이상의 실행시간이 걸린 쿼리를 로그로 남김
* 로그파일은 ./files/_db_slow_query.php 파일로 저장됨
**/
define('__LOG_SLOW_QUERY__', 0);
/**
* @brief ob_gzhandler를 이용한 압축 기능을 강제로 사용하거나 끄는 옵션
* 0 : 사용하지 않음
* 1 : 사용함
* 대부분의 서버에서는 문제가 없는데 특정 서버군에서 압축전송시 IE에서 오동작을 일으키는경우가 있음
**/
define('__OB_GZHANDLER_ENABLE__', 1);
/**
* @brief zbXE가 설치된 장소의 base path를 구함
**/
define('_XE_PATH_', str_replace('config/config.inc.php', '', str_replace('\\', '/', __FILE__)));
/**
* @brief 기본 설정에 우선하는 사용자 설정 파일
*/
if(file_exists(_XE_PATH_.'config/config.user.inc.php')) {
require _XE_PATH_.'config/config.user.inc.php';
}
/**
* @brief 디버깅 메시지 출력 (비트 )
* 0 : 디버그 메시지를 생성/ 출력하지 않음
* 1 : debugPrint() 함수를 통한 메시지 출력
* 2 : 소요시간, Request/Response info 출력
* 4 : DB 쿼리 내역 출력
**/
if(!defined('__DEBUG__')) define('__DEBUG__', 0);
/**
* @brief 디버그 메세지의 출력 장소
* 0 : files/_debug_message.php 연결하여 출력
* 1 : HTML 최하단에 주석으로 출력 (Response Method가 HTML )
* 2 : Firebug 콘솔에 출력 (PHP >= 5.2.0. Firebug/FirePHP 플러그인 필요)
**/
if(!defined('__DEBUG_OUTPUT__')) define('__DEBUG_OUTPUT__', 0);
/**
* @brief FirePHP 콘솔 브라우저 주석 출력 보안
* 0 : 제한 없음 (권장하지 않음)
* 1 : 지정한 IP 주소에만 허용
**/
if(!defined('__DEBUG_PROTECT__')) define('__DEBUG_PROTECT__', 1);
if(!defined('__DEBUG_PROTECT_IP__')) define('__DEBUG_PROTECT_IP__', '127.0.0.1');
/**
* @brief DB 오류 메세지 출력 정의
* 0 : 출력하지 않음
* 1 : files/_debug_db_query.php 연결하여 출력
**/
if(!defined('__DEBUG_DB_OUTPUT__')) define('__DEBUG_DB_OUTPUT__', 0);
/**
* @brief DB 쿼리중 정해진 시간을 넘기는 쿼리의 로그 남김
* 0 : 로그를 남기지 않음
* 0 이상 : 단위를 초로 하여 지정된 이상의 실행시간이 걸린 쿼리를 로그로 남김
* 로그파일은 ./files/_db_slow_query.php 파일로 저장됨
**/
if(!defined('__LOG_SLOW_QUERY__')) define('__LOG_SLOW_QUERY__', 0);
/**
* @brief ob_gzhandler를 이용한 압축 기능을 강제로 사용하거나 끄는 옵션
* 0 : 사용하지 않음
* 1 : 사용함
* 대부분의 서버에서는 문제가 없는데 특정 서버군에서 압축전송시 IE에서 오동작을 일으키는경우가 있음
**/
if(!defined('__OB_GZHANDLER_ENABLE__')) define('__OB_GZHANDLER_ENABLE__', 1);
/**
* @brief Firebug 콘솔 출력 사용시 관련 파일 require
**/
if(__DEBUG_OUTPUT__ == 2 && version_compare(phpversion(), '5.2', '>') == 1) {
require_once _XE_PATH_.'libs/FirePHPCore/FirePHP.class.php';
if((__DEBUG_OUTPUT__ == 2) && version_compare(PHP_VERSION, '5.2.0', '>=')) {
require _XE_PATH_.'libs/FirePHPCore/FirePHP.class.php';
}
/**
* @brief 간단하게 사용하기 위한 함수 정의한 파일 require
**/
require_once(_XE_PATH_.'config/func.inc.php');
require_once(_XE_PATH_.'config/func.inc.php');
if(__DEBUG__) define('__StartTime__', getMicroTime());
/**
* @brief 기본적인 class 파일 include
*
* php5 기반으로 바꾸게 되면 _autoload를 이용할 있기에 제거 대상
* @TODO : PHP5 기반으로 바꾸게 되면 _autoload() 이용할 있기에 제거 대상
**/
if(__DEBUG__) define('__ClassLoadStartTime__', getMicroTime());
require_once(_XE_PATH_.'classes/object/Object.class.php');
@ -104,4 +113,4 @@
require_once(_XE_PATH_.'classes/template/TemplateHandler.class.php');
require_once(_XE_PATH_.'classes/mail/Mail.class.php');
if(__DEBUG__) $GLOBALS['__elapsed_class_load__'] = getMicroTime() - __ClassLoadStartTime__;
?>
?>

View file

@ -395,40 +395,44 @@
* ./files/_debug_message.php 파일에 $buff 내용을 출력한다.
* tail -f ./files/_debug_message.php 하여 계속 살펴 있다
**/
function debugPrint($buff = null, $display_option = true) {
function debugPrint($debug_output = null, $display_option = true) {
if(!(__DEBUG__ & 1)) return;
static $firephp;
$bt = debug_backtrace();
if(is_array($bt)) $first = array_shift($bt);
$file_name = array_pop(explode(DIRECTORY_SEPARATOR, $first['file']));
$line_num = $first['line'];
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($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(__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '5.2.0', '>=')) {
if(!isset($firephp)) $firephp = FirePHP::getInstance(true);
$label = sprintf('%s:%d', $file_name, $line_num);
// FirePHP 옵션
if($display_option === 'TABLE') {
$label = $display_option;
}
$label = sprintf('[%s:%d] ', $file_name, $line_num);
if(__DEBUG_PROTECT__ == 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) {
$buff = '허용되지 않은 IP 입니다. config/config.inc.php 파일의 __DEBUG_PROTECT_IP__ 상수 값을 자신의 IP로 변경하세요.';
// FirePHP 옵션 체크
if($display_option === 'TABLE') $label = $display_option;
// __DEBUG_PROTECT__ 옵션으로 지정된 IP와 접근 IP가 동일한지 체크
if(__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR']) {
$debug_output = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php';
$label = null;
}
$firephp->fb($buff, $label);
$firephp->fb($debug_output, $label);
} else {
$debug_file = _XE_PATH_.'files/_debug_message.php';
$debug_output = sprintf("[%s %s:%d]\n%s\n", date('Y-m-d H:i:s'), $file_name, $line_num, print_r($debug_output, true));
if($display_option === true) $debug_output = str_repeat('=', 40)."\n".$debug_output.str_repeat('-', 40);
$debug_output = "\n<?php\n/*".$debug_output."*/\n?>\n";
if(@!$fp = fopen($debug_file, 'a')) return;
fwrite($fp, $debug_output);
fclose($fp);
}
}
/**
* @brief microtime() return
* @return float
@ -721,4 +725,4 @@
}
}
?>
?>