let us more easily debug difficult or intermittent issues that users may not report. Add a cron to report logged errors to appdb admins every night. Implement some basic unit tests for the new error logging code
93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
|
|
define(ERROR_SQL, "sql_error");
|
|
define(ERROR_GENERAL, "general_error");
|
|
|
|
class error_log
|
|
{
|
|
function log_error($sErrorType, $sLogText)
|
|
{
|
|
global $aClean;
|
|
|
|
/* dump the contents of $_REQUEST and $aClean to a variable */
|
|
/* so we can output that to the log entry. it should make it much easier */
|
|
/* to determine when and where the error took place */
|
|
ob_start();
|
|
echo "REQUEST:\n";
|
|
var_dump($_REQUEST);
|
|
echo "aClean:\n";
|
|
var_dump($aClean);
|
|
$sRequestText = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
$sQuery = 'INSERT INTO error_log (submitTime, userid, type, log_text, request_text, deleted) '.
|
|
"VALUES(?, '?', '?', '?', '?', '?')";
|
|
$hResult = query_parameters($sQuery,
|
|
"NOW()",
|
|
$_SESSION['current']->iUserId,
|
|
$sErrorType,
|
|
$sLogText,
|
|
$sRequestText,
|
|
'0');
|
|
}
|
|
|
|
function getEntryCount()
|
|
{
|
|
$sQuery = "SELECT count(*) as cnt FROM error_log WHERE deleted = '0'";
|
|
$hResult = query_parameters($sQuery);
|
|
$oRow = mysql_fetch_object($hResult);
|
|
return $oRow->cnt;
|
|
}
|
|
|
|
/* purge all of the current entries from the error log */
|
|
function flush()
|
|
{
|
|
$sQuery = "UPDATE error_log SET deleted='1'";
|
|
$hResult = query_parameters($sQuery);
|
|
|
|
if($hResult) return true;
|
|
else return false;
|
|
}
|
|
|
|
function mail_admins_error_log()
|
|
{
|
|
$sSubject = "Appdb error log\r\n";
|
|
$sEmail = User::get_notify_email_address_list(null, null); /* get list admins */
|
|
|
|
$sQuery = "SELECT * from error_log WHERE deleted='0' ORDER BY submitTime";
|
|
$hResult = query_parameters($sQuery);
|
|
|
|
$bEmpty = false;
|
|
if(mysql_num_rows($hResult) == 0)
|
|
$bEmpty = true;
|
|
|
|
$sMsg = "Log entries:\r\n";
|
|
$sMsg.= "\r\n";
|
|
|
|
$sMsg.= "Submit time userid type\r\n";
|
|
$sMsg.= "log_text\r\n";
|
|
$sMsg.= "request_text\r\n";
|
|
$sMsg.="----------------------------------\r\n\r\n";
|
|
|
|
/* append each log entry to $sMsg */
|
|
while($oRow = mysql_fetch_object($hResult))
|
|
{
|
|
$sMsg.=$oRow->submitTime." ".$oRow->userid." ".$oRow->type."\r\n";
|
|
$sMsg.= "---------------------\r\n";
|
|
$sMsg.=$oRow->log_text."\r\n";
|
|
$sMsg.= "---------------------\r\n";
|
|
$sMsg.=$oRow->request_text."\r\n\r\n";
|
|
}
|
|
|
|
/* if we had no entries we should indicate */
|
|
/* that the error log is empty */
|
|
if($bEmpty)
|
|
$sMsg = "The error log is empty.\r\n";
|
|
|
|
if($sEmail)
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
|
}
|
|
}
|
|
|
|
?>
|