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:
@@ -325,7 +325,7 @@ class Basic
|
||||
* all html tags will be stripped and <br> changed to \n
|
||||
* this is only used for debug output
|
||||
* @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
|
||||
{
|
||||
@@ -446,7 +446,6 @@ class Basic
|
||||
* prints a html formatted (pre) array
|
||||
* @param array $array any array
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
* DEPRCATE HARD LATER
|
||||
* @deprecated Use \CoreLibs\Debug\Support::printAr() instead
|
||||
*/
|
||||
public static function printAr(array $array): string
|
||||
|
||||
@@ -407,7 +407,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
}
|
||||
// integer is different
|
||||
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']).
|
||||
' | INT NULL: '.(string)isset($this->table_array[$column]['int_null']));
|
||||
if (isset($this->table_array[$column]['value']) &&
|
||||
|
||||
@@ -547,7 +547,7 @@ class IO extends \CoreLibs\Basic
|
||||
if ($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);
|
||||
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->__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');
|
||||
|
||||
@@ -427,16 +427,37 @@ class Logging
|
||||
if (!$this->doDebugTrigger('debug', $level)) {
|
||||
return false;
|
||||
}
|
||||
if (!isset($this->error_msg[$level])) {
|
||||
$this->error_msg[$level] = '';
|
||||
}
|
||||
// get the last class entry and wrie that
|
||||
$class = \CoreLibs\Debug\Support::getCallerClass();
|
||||
// get timestamp
|
||||
$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)) {
|
||||
$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: #c56c00;">'.$level.'</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)
|
||||
."</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;
|
||||
}
|
||||
|
||||
@@ -482,9 +480,7 @@ class Logging
|
||||
if (!is_array($error_msg)) {
|
||||
$error_msg = [];
|
||||
}
|
||||
foreach ($error_msg as $level => $msg) {
|
||||
$this->error_msg[$level] .= $msg;
|
||||
}
|
||||
array_push($this->error_msg, ...$error_msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -503,11 +499,11 @@ class Logging
|
||||
foreach ($this->error_msg as $level => $temp_debug_output) {
|
||||
if ($this->doDebugTrigger('debug', $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>] '
|
||||
.($string ? "<b>**** ".\CoreLibs\Convert\Html::htmlent($string)." ****</b>\n" : "")
|
||||
.($string ? "<b>**** ".\CoreLibs\Convert\Html::htmlent($string)." ****</br>\n" : "")
|
||||
.'</div>'
|
||||
.$temp_debug_output;
|
||||
.join('', $temp_debug_output);
|
||||
} // echo it out
|
||||
} // do printout
|
||||
} // for each level
|
||||
|
||||
Reference in New Issue
Block a user