mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 20:00:37 +02:00
BugFix query logging: ensure the
log only parses 'explain', not the original query.; install shutdown error handler for php; Resolve error reporting issue(s) by consolidating debug error reporting in a single Show_ALL() function.
This commit is contained in:
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/db_debug_class.php,v $
|
||||
| $Revision: 1.1.1.1 $
|
||||
| $Date: 2006-12-02 04:33:43 $
|
||||
| $Author: mcfly_e107 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2006-12-05 09:23:54 $
|
||||
| $Author: mrpete $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,7 @@ class e107_db_debug {
|
||||
var $scbbcodes = array();
|
||||
var $scbcount;
|
||||
var $deprecated_funcs = array();
|
||||
var $aLog = array(); // Generalized debug log (only seen during debug)
|
||||
|
||||
function e107_db_debug() {
|
||||
global $eTimingStart;
|
||||
@@ -46,6 +47,38 @@ class e107_db_debug {
|
||||
'DB Time' => 0,
|
||||
'DB Count' => 0
|
||||
);
|
||||
|
||||
register_shutdown_function('e107_debug_shutdown');
|
||||
}
|
||||
|
||||
//
|
||||
// Add your new Show function here so it will display in debug output!
|
||||
//
|
||||
function Show_All()
|
||||
{
|
||||
global $eTraffic;
|
||||
|
||||
$this->ShowIf('Debug Log', $this->Show_Log());
|
||||
$this->ShowIf('Traffic Counters', $eTraffic->Display());
|
||||
$this->ShowIf('Time Analysis', $this->Show_Performance());
|
||||
$this->ShowIf('SQL Analysis', $this->Show_SQL_Details());
|
||||
$this->ShowIf('Shortcodes / BBCode',$this->Show_SC_BB());
|
||||
$this->ShowIf('Paths', $this->Show_PATH());
|
||||
$this->ShowIf('Deprecated Function Usage', $this->Show_DEPRECATED());
|
||||
}
|
||||
|
||||
function ShowIf($title,$str)
|
||||
{
|
||||
global $ns;
|
||||
|
||||
if (!isset($ns)) {
|
||||
echo "Why did ns go away?<br/>";
|
||||
$ns = new e107table;
|
||||
}
|
||||
|
||||
if (strlen($str)) {
|
||||
$ns->tablerender($title, $str);
|
||||
}
|
||||
}
|
||||
|
||||
function Mark_Time($sMarker) { // Should move to traffic_class?
|
||||
@@ -82,14 +115,17 @@ class e107_db_debug {
|
||||
list($qtype,$args) = explode(" ", ltrim($query), 2);
|
||||
|
||||
$nFields=0;
|
||||
if (!strcasecmp($qtype,'SELECT')) {
|
||||
$bExplained = FALSE;
|
||||
if (!strcasecmp($qtype,'SELECT') || !strcasecmp($qtype,'(SELECT')) {
|
||||
$sQryRes=is_null($rli) ? mysql_query("EXPLAIN $query") : mysql_query("EXPLAIN $query", $rli);
|
||||
|
||||
if ($sQryRes) { // There's something to explain
|
||||
$nFields = mysql_num_fields($sQryRes);
|
||||
$bExplained = TRUE;
|
||||
}
|
||||
} else {
|
||||
$sQryRes = $origQryRes;
|
||||
$bExplained = FALSE;
|
||||
$nFields=0;
|
||||
}
|
||||
|
||||
@@ -106,7 +142,7 @@ class e107_db_debug {
|
||||
$t['nFields']=$nFields;
|
||||
$t['time']=$mytime;
|
||||
|
||||
if ($sQryRes != 1) {
|
||||
if ($bExplained) {
|
||||
$bRowHeaders=FALSE;
|
||||
while ($row = @mysql_fetch_assoc($sQryRes)) {
|
||||
if (!$bRowHeaders) {
|
||||
@@ -162,12 +198,12 @@ class e107_db_debug {
|
||||
if ($badCount) {
|
||||
$text .= "\n<table class='fborder'>\n";
|
||||
$text .= "<tr><td class='fcaption' colspan='2'><b>$badCount Query Errors!</b></td></tr>\n";
|
||||
$text .= "<tr><td class='fcaption'><b>Index</b></td><td class='fcaption'><b>Query</b></td></tr>\n";
|
||||
$text .= "<tr><td class='fcaption'><b>Index</b></td><td class='fcaption'><b>Query / Error</b></td></tr>\n";
|
||||
|
||||
foreach ($this->aSQLdetails as $idx => $cQuery) {
|
||||
if (!$cQuery['ok']) {
|
||||
$text .= "<tr><td class='forumheader3' style='text-align:right'>{$idx} </td>
|
||||
<td class='forumheader3'>".$cQuery['query']."</td></tr>\n";
|
||||
$text .= "<tr><td class='forumheader3' rowspan='2' style='text-align:right'>{$idx} </td>
|
||||
<td class='forumheader3'>".$cQuery['query']."</td></tr>\n<tr><td class='forumheader3'>".$cQuery['error']."</td></tr>\n";
|
||||
}
|
||||
}
|
||||
$text .= "\n</table><br/>\n";
|
||||
@@ -457,6 +493,98 @@ class e107_db_debug {
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Simple debug-level 'console' log
|
||||
// Record a "nice" debug message with
|
||||
// $db_debug->log("message");
|
||||
//
|
||||
function log($message,$TraceLev=1)
|
||||
{
|
||||
if (!E107_DBG_BASIC){
|
||||
return FALSE;
|
||||
}
|
||||
if ($TraceLev)
|
||||
{
|
||||
$bt = debug_backtrace();
|
||||
$this->aLog[] = array (
|
||||
'Message' => $message,
|
||||
'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'].$bt[$TraceLev]['type'].$bt[$TraceLev]['function'].'()' : $bt[$TraceLev]['function']).'()',
|
||||
'File' => $bt[$TraceLev]['file'],
|
||||
'Line' => $bt[$TraceLev]['line']
|
||||
);
|
||||
} else {
|
||||
$this->aLog[] = array (
|
||||
'Message' => $message,
|
||||
'Function' => '',
|
||||
'File' => '',
|
||||
'Line' => ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function Show_Log(){
|
||||
if (!E107_DBG_BASIC || !count($this->aLog)){
|
||||
return FALSE;
|
||||
}
|
||||
//
|
||||
// Dump the debug log
|
||||
//
|
||||
|
||||
$text .= "\n<table class='fborder'>\n";
|
||||
|
||||
$bRowHeaders=FALSE;
|
||||
|
||||
foreach ($this->aLog as $curLog)
|
||||
{
|
||||
if (!$bRowHeaders) {
|
||||
$bRowHeaders=TRUE;
|
||||
$text .= "<tr class='fcaption'><td><b>".implode("</b></td><td><b>", array_keys($curLog))."</b></td></tr>\n";
|
||||
}
|
||||
|
||||
$text .= "<tr class='forumheader3'><td>".implode(" </td><td>", array_values($curLog))." </td></tr>\n";
|
||||
}
|
||||
|
||||
$text .= "</table><br/>\n";
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
function e107_debug_shutdown()
|
||||
{
|
||||
global $error_handler,$e107_Clean_Exit,$In_e107_Footer,$ADMIN_DIRECTORY;
|
||||
if (isset($e107_Clean_Exit)) return;
|
||||
|
||||
if (!isset($In_e107_Footer))
|
||||
{
|
||||
if (defset('ADMIN_AREA'))
|
||||
{
|
||||
$filewanted=realpath(dirname(__FILE__)).'/../'.$ADMIN_DIRECTORY.'footer.php';
|
||||
require_once($filewanted);
|
||||
} else if (defset('USER_AREA'))
|
||||
{
|
||||
$filewanted=realpath(dirname(__FILE__)).'/../'.FOOTERF;
|
||||
require_once($filewanted);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Error while in the footer, or during startup, or during above processing
|
||||
//
|
||||
if (isset($e107_Clean_Exit)) return; // We've now sent a footer...
|
||||
|
||||
// echo isset($In_e107_Footer) ? "In footer" : "In startup".'<br>';
|
||||
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_flush();
|
||||
}
|
||||
if (isset($error_handler))
|
||||
{
|
||||
echo "<br /><div><h3>PHP Errors:</h3><br />".$error_handler->return_errors()."</div>\n";
|
||||
} else {
|
||||
echo "<b>e107 Shutdown while no error_handler available!</b>";
|
||||
}
|
||||
echo "</body></html>";
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/debug_handler.php,v $
|
||||
| $Revision: 1.1.1.1 $
|
||||
| $Date: 2006-12-02 04:33:43 $
|
||||
| $Author: mcfly_e107 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2006-12-05 09:24:18 $
|
||||
| $Author: mrpete $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -58,7 +58,7 @@ if (strstr(e_MENU, "debug") || isset($_COOKIE['e107_debug_level'])) {
|
||||
//
|
||||
|
||||
// Basic levels
|
||||
define('E107_DBG_BASIC', (E107_DEBUG_LEVEL & 1)); // basics: worst php errors, sql errors, etc
|
||||
define('E107_DBG_BASIC', (E107_DEBUG_LEVEL & 1)); // basics: worst php errors, sql errors, log, etc
|
||||
define('E107_DBG_SQLQUERIES', (E107_DEBUG_LEVEL & 2)); // display all sql queries
|
||||
define('E107_DBG_TRAFFIC', (E107_DEBUG_LEVEL & 4)); // display traffic counters
|
||||
define('E107_DBG_FILLIN8', (E107_DEBUG_LEVEL & 8)); // fill in what it is
|
||||
@@ -73,9 +73,9 @@ define('E107_DBG_SQLDETAILS', (E107_DEBUG_LEVEL & 512)); // detailed sql an
|
||||
define('E107_DBG_PATH', (E107_DEBUG_LEVEL & 1024)); // show e107 predefined paths
|
||||
define('E107_DBG_BBSC', (E107_DEBUG_LEVEL & 2048)); // Show BBCode/ Shortcode usage in postings
|
||||
define('E107_DBG_SC', (E107_DEBUG_LEVEL & 4096)); // Dump (inline) SC filenames as used
|
||||
define('E107_DBG_FILLIN8192', (E107_DEBUG_LEVEL & 8192)); // fill in what it is
|
||||
define('E107_DBG_ERRBACKTRACE', (E107_DEBUG_LEVEL & 8192)); // show backtrace for php errors
|
||||
define('E107_DBG_DEPRECATED', (E107_DEBUG_LEVEL & 16384)); // Show use of deprecated functions
|
||||
define('E107_DBG_ALLERRORS', (E107_DEBUG_LEVEL & 32768)); // show ALL errors//...
|
||||
define('E107_DBG_ALLERRORS', (E107_DEBUG_LEVEL & 32768)); // show ALL php errors (including notices), not just fatal issues
|
||||
|
||||
class e107_debug {
|
||||
|
||||
@@ -87,30 +87,45 @@ class e107_debug {
|
||||
'all' => 255, // all basics
|
||||
'basic' => 255, // all basics
|
||||
'b' => 255, // all basics
|
||||
'warn' => 1, // just warnings, parse errrors, etc
|
||||
'warn' => 1, // just php warnings, parse errrors, debug log, etc
|
||||
'showsql' => 2, // sql basics
|
||||
'counts' => 4, // traffic counters
|
||||
|
||||
'detail' => 32767, // all details
|
||||
'd' => 32767, // all details
|
||||
'time' => 256, // time details
|
||||
'sql' => 512, // sql details
|
||||
'time' => 257, // time details and php errors
|
||||
'sql' => 513, // sql details and php errors
|
||||
'paths' => 1024, // dump path strings
|
||||
'bbsc' => 2048, // show bb and sc details
|
||||
'sc' => 4096, // Shortcode paths dumped inline
|
||||
'backtrace' => 8192, // show backtrace when PHP has errors
|
||||
'deprecated' => 16384, // show if code is using deprecated functions
|
||||
'notice' => 32768, // you REALLY don't want all this, do you?
|
||||
'everything'=> 65535,
|
||||
'everything'=> 61439, //(65535-4096) everything we know, and the rumors too
|
||||
// (but shortcode paths removed: inline debug breaks pages!
|
||||
);
|
||||
|
||||
function e107_debug() {
|
||||
if (preg_match('/debug(=?)(.*?),?(\+|stick|-|unstick|$)/', e_MENU, $debug_param) || isset($_COOKIE['e107_debug_level'])) {
|
||||
$dVals=0;
|
||||
if (isset($_COOKIE['e107_debug_level'])) {
|
||||
$dVal = substr($_COOKIE['e107_debug_level'],6);
|
||||
$dVals = substr($_COOKIE['e107_debug_level'],6);
|
||||
}
|
||||
if (preg_match('/debug(=?)(.*?),?(\+|stick|-|unstick|$)/', e_MENU)) {
|
||||
$dVal = $debug_param[1] == '=' ? $debug_param[2] : 'everything';
|
||||
$dVals = $debug_param[1] == '=' ? $debug_param[2] : 'everything';
|
||||
}
|
||||
|
||||
$aDVal = explode('.',$dVals); // support multiple values, OR'd together
|
||||
$dVal = 0;
|
||||
foreach ($aDVal as $curDVal)
|
||||
{
|
||||
if (isset($this->aDebugShortcuts[$curDVal])) {
|
||||
$dVal |= $this->aDebugShortcuts[$curDVal];
|
||||
} else {
|
||||
$dVal |= $curDVal;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($debug_param[3]))
|
||||
{
|
||||
if ($debug_param[3] == '+' || $debug_param[3] == 'stick')
|
||||
@@ -123,13 +138,9 @@ class e107_debug {
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->aDebugShortcuts[$dVal])) {
|
||||
$this->debug_level = $this->aDebugShortcuts[$dVal];
|
||||
} else {
|
||||
$this->debug_level = $dVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function set_error_reporting() {
|
||||
}
|
||||
|
@@ -12,9 +12,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
|
||||
| $Revision: 1.1.1.1 $
|
||||
| $Date: 2006-12-02 04:33:47 $
|
||||
| $Author: mcfly_e107 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2006-12-05 09:24:18 $
|
||||
| $Author: mrpete $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -27,8 +27,8 @@ $db_mySQLQueryCount = 0; // Global total number of db object queries (all db's)
|
||||
* MySQL Abstraction class
|
||||
*
|
||||
* @package e107
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @author $Author: mcfly_e107 $
|
||||
* @version $Revision: 1.2 $
|
||||
* @author $Author: mrpete $
|
||||
*/
|
||||
class db {
|
||||
|
||||
@@ -345,7 +345,6 @@ class db {
|
||||
} else {
|
||||
$this->dbError('db_Fetch');
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user