Update Debug\Logger for some simpler code
All strings are written to an array and not string append. Group debug write/debug echo better to make it more simple. Fixed bug with echo output in logging Also set debug to be deprecated for phan testing
This commit is contained in:
@@ -3,11 +3,12 @@
|
|||||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
// all the settings are overruled by config
|
||||||
$DEBUG_ALL = 1;
|
$DEBUG_ALL_OVERRIDE = true; // set to 1 to debug on live/remote server locations
|
||||||
$PRINT_ALL = 0;
|
$DEBUG_ALL = true;
|
||||||
|
$PRINT_ALL = false;
|
||||||
$ECHO_ALL = true;
|
$ECHO_ALL = true;
|
||||||
$DB_DEBUG = 1;
|
$DB_DEBUG = true;
|
||||||
|
|
||||||
if ($DEBUG_ALL) {
|
if ($DEBUG_ALL) {
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
@@ -26,7 +27,7 @@ if (!defined('SET_SESSION_NAME')) {
|
|||||||
// define log file id
|
// define log file id
|
||||||
$LOG_FILE_ID = 'classTest-debug';
|
$LOG_FILE_ID = 'classTest-debug';
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
// override ECHO ALL FALSE
|
||||||
$ECHO_ALL = true;
|
$ECHO_ALL = true;
|
||||||
|
|
||||||
use CoreLibs\Debug\Support as DebugSupport;
|
use CoreLibs\Debug\Support as DebugSupport;
|
||||||
@@ -53,7 +54,10 @@ print "V-S::PRINTAR: ".$debug_support_class::printAr(['Foo', 'Bar'])."<br>";
|
|||||||
|
|
||||||
// debug
|
// debug
|
||||||
print "C->DEBUG: ".$debug->debug('CLASS-TEST-DEBUG', 'Class Test Debug')."<br>";
|
print "C->DEBUG: ".$debug->debug('CLASS-TEST-DEBUG', 'Class Test Debug')."<br>";
|
||||||
|
print "C->DEBUG(html): ".$debug->debug('CLASS-TEST-DEBUG', 'HTML TAG<br><b>BOLD</b>')."<br>";
|
||||||
|
print "C->DEBUG(html,strip): ".$debug->debug('CLASS-TEST-DEBUG', 'HTML TAG<br><b>BOLD</b>', true)."<br>";
|
||||||
print "C->PRINTERRORMSG: <br>".$debug->printErrorMsg()."<br>";
|
print "C->PRINTERRORMSG: <br>".$debug->printErrorMsg()."<br>";
|
||||||
|
echo "<b>CLASS DEBUG CALL</b><br>";
|
||||||
|
|
||||||
class TestL
|
class TestL
|
||||||
{
|
{
|
||||||
@@ -62,15 +66,40 @@ class TestL
|
|||||||
{
|
{
|
||||||
$this->log = new CoreLibs\Debug\Logging();
|
$this->log = new CoreLibs\Debug\Logging();
|
||||||
}
|
}
|
||||||
public function test()
|
public function test(string $ts = null)
|
||||||
{
|
{
|
||||||
$this->log->debug('TESTL', 'Logging in class testL');
|
print "* GETCALLERCLASS(INSIDE CLASS): ".\CoreLibs\Debug\Support::getCallerClass()."<br>";
|
||||||
print "IN TestL->test: <br>".$this->log->printErrorMsg()."<br>";
|
$this->log->debug('TESTL', 'Logging in class testL'.($ts !== null ? ': '.$ts : ''));
|
||||||
|
$this->log->debug('TESTL', 'Some other message');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class TestR extends TestL
|
||||||
|
{
|
||||||
|
public $foo;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
public function subTest()
|
||||||
|
{
|
||||||
|
print "** GETCALLERCLASS(INSIDE EXTND CLASS): ".\CoreLibs\Debug\Support::getCallerClass()."<br>";
|
||||||
|
$this->log->debug('TESTR', 'Logging in class testR (extends testL)');
|
||||||
|
$this->test('TESTR INSIDE');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tl = new TestL();
|
$tl = new TestL();
|
||||||
print "CLASS SUB: DEBUG: ".$tl->test()."<br>";
|
print "CLASS: LOG ECHO: ".(string)$tl->log->getLogLevelAll('echo')."<br>";
|
||||||
|
print "CLASS: DEBUG: ".$tl->test()."<br>";
|
||||||
|
print "CLASS: PRINTERRORMSG: <br>".$tl->log->printErrorMsg()."<br>";
|
||||||
|
$tr = new TestR();
|
||||||
|
print "CLASS: LOG ECHO: ".(string)$tr->log->getLogLevelAll('echo')."<br>";
|
||||||
|
print "CLASS EXTEND: DEBUG/tl: ".$tr->test('TESTR OUTSIDE')."<br>";
|
||||||
|
print "CLASS EXTEND: DEBUG/tr: ".$tr->subTest()."<br>";
|
||||||
|
print "CLASS EXTEND: PRINTERRORMSG: <br>".$tr->log->printErrorMsg()."<br>";
|
||||||
|
|
||||||
|
print "GETCALLERCLASS(NON CLASS): ".\CoreLibs\Debug\Support::getCallerClass()."<br>";
|
||||||
|
|
||||||
// fdebug
|
// fdebug
|
||||||
print "S::FSETFILENAME: ".FileWriter::fsetFilename('class_test_debug_file.log')."<br>";
|
print "S::FSETFILENAME: ".FileWriter::fsetFilename('class_test_debug_file.log')."<br>";
|
||||||
@@ -78,7 +107,8 @@ print "S::FDEBUG: ".FileWriter::fdebug('CLASS TEST DEBUG FILE: '.date('Y-m-d H:i
|
|||||||
|
|
||||||
// error message
|
// error message
|
||||||
// future DEPRECATED
|
// future DEPRECATED
|
||||||
$basic->debug('BASIC CLASS', 'Debug test');
|
// $basic->debug('BASIC CLASS', 'Debug test');
|
||||||
|
$basic->log->debug('BASIC CLASS', 'Debug test');
|
||||||
print "BASIC:<br>".$basic->log->printErrorMsg();
|
print "BASIC:<br>".$basic->log->printErrorMsg();
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ class Basic
|
|||||||
* all html tags will be stripped and <br> changed to \n
|
* all html tags will be stripped and <br> changed to \n
|
||||||
* this is only used for debug output
|
* this is only used for debug output
|
||||||
* @return void has no return
|
* @return void has no return
|
||||||
* @[TODO]deprecated Use $basic->log->debug() instead
|
* @deprecated Use $basic->log->debug() instead
|
||||||
*/
|
*/
|
||||||
public function debug(string $level, string $string, bool $strip = false): void
|
public function debug(string $level, string $string, bool $strip = false): void
|
||||||
{
|
{
|
||||||
@@ -446,7 +446,6 @@ class Basic
|
|||||||
* prints a html formatted (pre) array
|
* prints a html formatted (pre) array
|
||||||
* @param array $array any array
|
* @param array $array any array
|
||||||
* @return string formatted array for output with <pre> tag added
|
* @return string formatted array for output with <pre> tag added
|
||||||
* DEPRCATE HARD LATER
|
|
||||||
* @deprecated Use \CoreLibs\Debug\Support::printAr() instead
|
* @deprecated Use \CoreLibs\Debug\Support::printAr() instead
|
||||||
*/
|
*/
|
||||||
public static function printAr(array $array): string
|
public static function printAr(array $array): string
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
}
|
}
|
||||||
// integer is different
|
// integer is different
|
||||||
if (isset($this->table_array[$column]['int']) || isset($this->table_array[$column]['int_null'])) {
|
if (isset($this->table_array[$column]['int']) || isset($this->table_array[$column]['int_null'])) {
|
||||||
$this->debug('write_check', '['.$column.']['.$this->table_array[$column]['value'].']['.$this->table_array[$column]['type'].'] '.
|
$this->log->debug('write_check', '['.$column.']['.$this->table_array[$column]['value'].']['.$this->table_array[$column]['type'].'] '.
|
||||||
'VALUE SET: '.(string)isset($this->table_array[$column]['value']).
|
'VALUE SET: '.(string)isset($this->table_array[$column]['value']).
|
||||||
' | INT NULL: '.(string)isset($this->table_array[$column]['int_null']));
|
' | INT NULL: '.(string)isset($this->table_array[$column]['int_null']));
|
||||||
if (isset($this->table_array[$column]['value']) &&
|
if (isset($this->table_array[$column]['value']) &&
|
||||||
|
|||||||
@@ -547,7 +547,7 @@ class IO extends \CoreLibs\Basic
|
|||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
$prefix .= '- ';
|
$prefix .= '- ';
|
||||||
}
|
}
|
||||||
$this->debug($debug_id, $prefix.$error_string, true);
|
$this->log->debug($debug_id, $prefix.$error_string, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1624,7 +1624,7 @@ class IO extends \CoreLibs\Basic
|
|||||||
}
|
}
|
||||||
$result = $this->db_functions->__dbExecute($stm_name, $data);
|
$result = $this->db_functions->__dbExecute($stm_name, $data);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.\CoreLibs\Debug\Support::printAr($data));
|
$this->log->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.\CoreLibs\Debug\Support::printAr($data));
|
||||||
$this->error_id = 22;
|
$this->error_id = 22;
|
||||||
$this->__dbError($this->prepare_cursor[$stm_name]['result']);
|
$this->__dbError($this->prepare_cursor[$stm_name]['result']);
|
||||||
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Execution failed</span>', 'DB_ERROR');
|
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Execution failed</span>', 'DB_ERROR');
|
||||||
|
|||||||
@@ -427,16 +427,37 @@ class Logging
|
|||||||
if (!$this->doDebugTrigger('debug', $level)) {
|
if (!$this->doDebugTrigger('debug', $level)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isset($this->error_msg[$level])) {
|
|
||||||
$this->error_msg[$level] = '';
|
|
||||||
}
|
|
||||||
// get the last class entry and wrie that
|
// get the last class entry and wrie that
|
||||||
$class = \CoreLibs\Debug\Support::getCallerClass();
|
$class = \CoreLibs\Debug\Support::getCallerClass();
|
||||||
// get timestamp
|
// get timestamp
|
||||||
$timestamp = \CoreLibs\Debug\Support::printTime();
|
$timestamp = \CoreLibs\Debug\Support::printTime();
|
||||||
// HTML string, create only if we have echo
|
// same string put for print (no html data inside)
|
||||||
|
// write to file if set
|
||||||
|
$this->writeErrorMsg(
|
||||||
|
$level,
|
||||||
|
'['.$timestamp.'] '
|
||||||
|
.'['.$this->host_name.'] '
|
||||||
|
.'['.\CoreLibs\Get\System::getPageName(2).'] '
|
||||||
|
.'['.$this->running_uid.'] '
|
||||||
|
.'{'.$class.'} '
|
||||||
|
.'<'.$level.'> - '
|
||||||
|
// if stripping all html, etc is requested, only for write error msg
|
||||||
|
.($strip ?
|
||||||
|
// find any <br> and replace them with \n
|
||||||
|
// strip rest of html elements (base only)
|
||||||
|
preg_replace("/(<\/?)(\w+)([^>]*>)/", '[\\2]', str_replace('<br>', "\n", $string)) :
|
||||||
|
$string
|
||||||
|
)
|
||||||
|
."\n"
|
||||||
|
);
|
||||||
|
// write to error level msg array if there is an echo request
|
||||||
if ($this->doDebugTrigger('echo', $level)) {
|
if ($this->doDebugTrigger('echo', $level)) {
|
||||||
$error_string = '<div>'
|
// init if not set
|
||||||
|
if (!isset($this->error_msg[$level])) {
|
||||||
|
$this->error_msg[$level] = [];
|
||||||
|
}
|
||||||
|
// HTML string
|
||||||
|
$this->error_msg[$level][] = '<div>'
|
||||||
.'[<span style="font-weight: bold; color: #5e8600;">'.$timestamp.'</span>] '
|
.'[<span style="font-weight: bold; color: #5e8600;">'.$timestamp.'</span>] '
|
||||||
.'[<span style="font-weight: bold; color: #c56c00;">'.$level.'</span>] '
|
.'[<span style="font-weight: bold; color: #c56c00;">'.$level.'</span>] '
|
||||||
.'[<span style="color: #b000ab;">'.$this->host_name.'</span>] '
|
.'[<span style="color: #b000ab;">'.$this->host_name.'</span>] '
|
||||||
@@ -445,29 +466,6 @@ class Logging
|
|||||||
.'{<span style="font-style: italic; color: #928100;">'.$class.'</span>} - '.\CoreLibs\Convert\Html::htmlent($string)
|
.'{<span style="font-style: italic; color: #928100;">'.$class.'</span>} - '.\CoreLibs\Convert\Html::htmlent($string)
|
||||||
."</div><!--#BR#-->";
|
."</div><!--#BR#-->";
|
||||||
}
|
}
|
||||||
// if stripping all html, etc is requested
|
|
||||||
if ($strip) {
|
|
||||||
// find any <br> and replace them with \n
|
|
||||||
$string = str_replace('<br>', "\n", $string);
|
|
||||||
// strip rest of html elements
|
|
||||||
$string = preg_replace("/(<\/?)(\w+)([^>]*>)/", '', $string);
|
|
||||||
}
|
|
||||||
// same string put for print (no html data inside)
|
|
||||||
$error_string_print =
|
|
||||||
'['.$timestamp.'] '
|
|
||||||
.'['.$this->host_name.'] '
|
|
||||||
.'['.\CoreLibs\Get\System::getPageName(2).'] '
|
|
||||||
.'['.$this->running_uid.'] '
|
|
||||||
.'{'.$class.'} '
|
|
||||||
.'<'.$level.'> - '
|
|
||||||
.$string;
|
|
||||||
$error_string_print .= "\n";
|
|
||||||
// write to file if set
|
|
||||||
$this->writeErrorMsg($level, $error_string_print);
|
|
||||||
// write to error level
|
|
||||||
if ($this->doDebugTrigger('echo', $level)) {
|
|
||||||
$this->error_msg[$level] .= $error_string;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,9 +480,7 @@ class Logging
|
|||||||
if (!is_array($error_msg)) {
|
if (!is_array($error_msg)) {
|
||||||
$error_msg = [];
|
$error_msg = [];
|
||||||
}
|
}
|
||||||
foreach ($error_msg as $level => $msg) {
|
array_push($this->error_msg, ...$error_msg);
|
||||||
$this->error_msg[$level] .= $msg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -503,11 +499,11 @@ class Logging
|
|||||||
foreach ($this->error_msg as $level => $temp_debug_output) {
|
foreach ($this->error_msg as $level => $temp_debug_output) {
|
||||||
if ($this->doDebugTrigger('debug', $level)) {
|
if ($this->doDebugTrigger('debug', $level)) {
|
||||||
if ($this->doDebugTrigger('echo', $level)) {
|
if ($this->doDebugTrigger('echo', $level)) {
|
||||||
$string_output = '<div style="font-size: 12px;">'
|
$string_output .= '<div style="font-size: 12px;">'
|
||||||
.'[<span style="font-style: italic; color: #c56c00;">'.$level.'</span>] '
|
.'[<span style="font-style: italic; color: #c56c00;">'.$level.'</span>] '
|
||||||
.($string ? "<b>**** ".\CoreLibs\Convert\Html::htmlent($string)." ****</b>\n" : "")
|
.($string ? "<b>**** ".\CoreLibs\Convert\Html::htmlent($string)." ****</br>\n" : "")
|
||||||
.'</div>'
|
.'</div>'
|
||||||
.$temp_debug_output;
|
.join('', $temp_debug_output);
|
||||||
} // echo it out
|
} // echo it out
|
||||||
} // do printout
|
} // do printout
|
||||||
} // for each level
|
} // for each level
|
||||||
|
|||||||
Reference in New Issue
Block a user