forked from Wavyzz/dolibarr
Qual: Fix WARNING messages in syslog - add getCallerInfoString() (#31351)
* Qual: Fix dolIsTms() call with empty string # Qual: Fix dolIsTms() call with empty string The dolibarr log indicated that dolIsTms() was called with the empty string: - Add code to log the caller in the log; - Fix the dolIsTms() calls by updating project/element.php * Fix comparison of ''<0 # Fix comparison of ''<0 As ''<0 is true, non-existing errors were added resulting in Try to add a message in stack, but value to add is empty message in the log.
This commit is contained in:
@@ -372,7 +372,7 @@ function isModEnabled($module)
|
||||
function isDolTms($timestamp)
|
||||
{
|
||||
if ($timestamp === '') {
|
||||
dol_syslog('Using empty string for a timestamp is deprecated, prefer use of null when calling page '.$_SERVER["PHP_SELF"], LOG_NOTICE);
|
||||
dol_syslog('Using empty string for a timestamp is deprecated, prefer use of null when calling page '.$_SERVER["PHP_SELF"] . getCallerInfoString(), LOG_NOTICE);
|
||||
return false;
|
||||
}
|
||||
if (is_null($timestamp) || !is_numeric($timestamp)) {
|
||||
@@ -2186,6 +2186,25 @@ function dol_ucwords($string, $encoding = "UTF-8")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get caller info as a string that can be appended to a log message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getCallerInfoString()
|
||||
{
|
||||
$backtrace = debug_backtrace();
|
||||
$msg = "";
|
||||
if (count($backtrace) >= 2) {
|
||||
$trace = $backtrace[1];
|
||||
if (isset($trace['file'], $trace['line'])) {
|
||||
$msg = " From {$trace['file']}:{$trace['line']}.";
|
||||
}
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write log message into outputs. Possible outputs can be:
|
||||
* SYSLOG_HANDLERS = ["mod_syslog_file"] file name is then defined by SYSLOG_FILE
|
||||
@@ -9891,7 +9910,7 @@ function setEventMessage($mesgs, $style = 'mesgs', $noduplicate = 0, $attop = 0)
|
||||
function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $noduplicate = 0, $attop = 0)
|
||||
{
|
||||
if (empty($mesg) && empty($mesgs)) {
|
||||
dol_syslog("Try to add a message in stack, but value to add is empty message", LOG_WARNING);
|
||||
dol_syslog("Try to add a message in stack, but value to add is empty message" . getCallerInfoString(), LOG_WARNING);
|
||||
} else {
|
||||
if ($messagekey) {
|
||||
// Complete message with a js link to set a cookie "DOLHIDEMESSAGE".$messagekey;
|
||||
|
||||
Reference in New Issue
Block a user