diff --git a/common/defaults/config.php b/common/defaults/config.php index 1e65f7e7c..fa353d3af 100644 --- a/common/defaults/config.php +++ b/common/defaults/config.php @@ -100,6 +100,7 @@ return array( 'display_type' => array('comment'), 'display_content' => array('request_info', 'entries', 'errors', 'queries'), 'display_to' => 'admin', + 'query_comment' => false, 'write_error_log' => 'fatal', 'allow' => array(), ), diff --git a/common/framework/db.php b/common/framework/db.php index 213addeea..4d1d0c9ba 100644 --- a/common/framework/db.php +++ b/common/framework/db.php @@ -42,6 +42,7 @@ class DB protected $_query_id = ''; protected $_errno = 0; protected $_errstr = ''; + protected $_debug_comment = false; /** * Transaction level. @@ -127,6 +128,9 @@ class DB // Get the DB version. $this->db_version = $this->_handle->getAttribute(\PDO::ATTR_SERVER_VERSION); + + // Cache the debug comment setting. + $this->_debug_comment = config('debug.query_comment') ? true : false; } /** @@ -154,6 +158,12 @@ class DB // Add table prefixes to the query string. $statement = $this->addPrefixes($statement); + // Add the debug comment. + if ($this->_debug_comment) + { + $statement .= "\n" . sprintf('/* prepare() %s */', \RX_CLIENT_IP); + } + // Create and return a prepared statement. $this->_last_stmt = $this->_handle->prepare($statement, $driver_options); return $this->_last_stmt; @@ -185,6 +195,12 @@ class DB // Add table prefixes to the query string. $query_string = $this->addPrefixes($query_string); + // Add the debug comment. + if ($this->_debug_comment) + { + $query_string .= "\n" . sprintf('/* query() %s */', \RX_CLIENT_IP); + } + // Execute either a prepared statement or a regular query depending on whether there are arguments. if (count($args)) { @@ -315,6 +331,11 @@ class DB // Prepare and execute the main query. try { + if ($this->_debug_comment) + { + $query_string .= "\n" . sprintf('/* %s %s */', $query_id, \RX_CLIENT_IP); + } + $this->_query_id = $query_id; if (count($query_params)) { @@ -395,6 +416,11 @@ class DB // Prepare and execute the query. try { + if ($this->_debug_comment) + { + $query_string .= "\n" . sprintf('/* %s %s */', $query_id, \RX_CLIENT_IP); + } + if (count($query_params)) { $this->_last_stmt = $this->_handle->prepare($query_string); @@ -457,6 +483,11 @@ class DB */ public function _query($query_string) { + if ($this->_debug_comment) + { + $query_string .= "\n" . sprintf('/* _query() %s */', \RX_CLIENT_IP); + } + $this->_last_stmt = $this->_handle->query($query_string); return $this->_last_stmt; } @@ -1084,7 +1115,7 @@ class DB // Compose the basic structure of the log entry. $result = array( - 'query' => $query, + 'query' => preg_replace('!\n/\* .+ \*/$!s', '', $query), 'query_id' => $this->_query_id, 'connection' => $this->_type, 'elapsed_time' => sprintf('%0.5f', $elapsed_time), diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index de838b958..3ca6f7f73 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -880,6 +880,7 @@ class adminAdminController extends admin Rhymix\Framework\Config::set('debug.log_slow_remote_requests', max(0, floatval($vars->debug_log_slow_remote_requests))); Rhymix\Framework\Config::set('debug.display_type', $display_type); Rhymix\Framework\Config::set('debug.display_to', strval($vars->debug_display_to) ?: 'admin'); + Rhymix\Framework\Config::set('debug.query_comment', $vars->debug_query_comment === 'Y'); Rhymix\Framework\Config::set('debug.write_error_log', strval($vars->debug_write_error_log) ?: 'fatal'); // Debug content diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index 273c76019..9bb8b53e6 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -626,6 +626,7 @@ class adminAdminView extends admin Context::set('debug_display_type', (array)Rhymix\Framework\Config::get('debug.display_type')); Context::set('debug_display_content', Rhymix\Framework\Config::get('debug.display_content')); Context::set('debug_display_to', Rhymix\Framework\Config::get('debug.display_to')); + Context::set('debug_query_comment', Rhymix\Framework\Config::get('debug.query_comment')); Context::set('debug_write_error_log', Rhymix\Framework\Config::get('debug.write_error_log')); // IP access control diff --git a/modules/admin/lang/en.php b/modules/admin/lang/en.php index 545af3f3f..12da002a3 100644 --- a/modules/admin/lang/en.php +++ b/modules/admin/lang/en.php @@ -230,6 +230,7 @@ $lang->debug_display_to_admin = 'Administrator only'; $lang->debug_display_to_ip = 'Visitors from IP adresses listed below'; $lang->debug_display_to_everyone = 'Everyone'; $lang->debug_log_filename = 'Log filename'; +$lang->debug_query_comment = 'Add Comment to Queries'; $lang->debug_write_error_log = 'Write to Error Log'; $lang->debug_write_error_log_all = 'All errors and warnings'; $lang->debug_write_error_log_fatal = 'Fatal errors only'; @@ -237,6 +238,7 @@ $lang->debug_write_error_log_none = 'None'; $lang->about_debug_log_filename = 'YYYYMMDD in the filename will be replaced with the current date.
It is recommended to split the log file by date to prevent it from getting too large.'; $lang->about_debug_write_error_log = 'Select how much information will be recorded in the PHP error log.
Error logs are recorded even if debugging is disabled in Rhymix.'; $lang->about_debug_error_log_path = 'The PHP error log is currently located at: %s'; +$lang->about_debug_query_comment = 'Add a comment containing the query name and IP address to every SQL statement. This may help you determine where slow queries are coming from.'; $lang->msg_debug_log_filename_not_writable = 'Rhymix cannot write log files in the specified path.'; $lang->debug_allowed_ip = 'Allowed IP addresses'; $lang->seo_main_title = 'Main Page Title'; diff --git a/modules/admin/lang/ko.php b/modules/admin/lang/ko.php index 3c6d33136..716839d96 100644 --- a/modules/admin/lang/ko.php +++ b/modules/admin/lang/ko.php @@ -226,6 +226,7 @@ $lang->debug_display_to_admin = '관리자에게만 표시'; $lang->debug_display_to_ip = '아래 IP의 방문자에게만 표시'; $lang->debug_display_to_everyone = '모두에게 표시'; $lang->debug_log_filename = '디버그 정보 기록 파일'; +$lang->debug_query_comment = '쿼리에 주석 추가'; $lang->debug_write_error_log = '에러 로그에 기록'; $lang->debug_write_error_log_all = '모든 에러와 경고를 기록'; $lang->debug_write_error_log_fatal = '치명적인 에러만 기록'; @@ -233,6 +234,7 @@ $lang->debug_write_error_log_none = '기록하지 않음'; $lang->about_debug_log_filename = '파일명에 YYYYMMDD가 포함된 경우 날짜별로 파일을 분리하여 기록합니다.
파일을 분리하지 않으면 용량이 매우 커질 수 있으니 주의하십시오.'; $lang->about_debug_write_error_log = 'PHP 에러 로그에 얼마나 많은 정보를 기록할지 선택할 수 있습니다.
오래된 서드파티 자료를 사용하시는 경우 경고(E_WARNING)가 많이 발생할 수 있으니 이 설정을 적절히 조정하십시오.
디버그 기능을 사용하지 않더라도 에러 로그는 항상 기록됩니다.'; $lang->about_debug_error_log_path = '현재 설정된 PHP 에러 로그 경로는 %s 입니다.'; +$lang->about_debug_query_comment = '쿼리명과 IP 주소를 포함하는 주석을 모든 쿼리에 추가하여, 부하를 유발하는 쿼리 및 방문자를 DB에서 쉽게 파악할 수 있도록 합니다.'; $lang->msg_debug_log_filename_not_writable = '지정한 경로에 로그 파일을 작성할 수 없습니다.'; $lang->debug_allowed_ip = '디버그 허용 IP'; $lang->seo_main_title = '메인화면 제목'; diff --git a/modules/admin/tpl/config_debug.html b/modules/admin/tpl/config_debug.html index ecbffa039..723b3344c 100644 --- a/modules/admin/tpl/config_debug.html +++ b/modules/admin/tpl/config_debug.html @@ -87,6 +87,14 @@ +
+ +
+ + +

{$lang->about_debug_query_comment}

+
+