From f1868ee1626426ce8517bbb4ac92472b74d03e39 Mon Sep 17 00:00:00 2001 From: Etienne BENDER Date: Mon, 9 Dec 2024 10:50:29 +0100 Subject: [PATCH 1/5] Replace dol_syslog throws by default log level --- htdocs/core/lib/functions.lib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index dd1536e1245..4c423494196 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1658,8 +1658,11 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = if (!empty($message)) { // Test log level $logLevels = array(LOG_EMERG=>'EMERG', LOG_ALERT=>'ALERT', LOG_CRIT=>'CRITICAL', LOG_ERR=>'ERR', LOG_WARNING=>'WARN', LOG_NOTICE=>'NOTICE', LOG_INFO=>'INFO', LOG_DEBUG=>'DEBUG'); + $defaultLogLevel = getDolGlobalInt('DEFAULT_SYSLOG_LEVEL', $logLevels[LOG_ERR]); + if (!array_key_exists($level, $logLevels)) { - throw new Exception('Incorrect log level'); + dol_syslog('The given log level does not correspond to any of the available levels: '.$level, LOG_ERR); + $level = $defaultLogLevel; } if ($level > $conf->global->SYSLOG_LEVEL) { return; From a96d13d5aaf7f81bdf57aa7b445e425ee954bd12 Mon Sep 17 00:00:00 2001 From: Etienne BENDER Date: Mon, 9 Dec 2024 10:56:35 +0100 Subject: [PATCH 2/5] Add translation for bad log level --- htdocs/core/lib/functions.lib.php | 7 +++---- htdocs/langs/en_US/errors.lang | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4c423494196..19839800a7a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1627,7 +1627,7 @@ function dol_ucwords($string, $encoding = "UTF-8") */ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = '', $restricttologhandler = '', $logcontext = null) { - global $conf, $user, $debugbar; + global $conf, $user, $debugbar, $langs; // If syslog module enabled if (empty($conf->syslog->enabled)) { @@ -1658,11 +1658,10 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = if (!empty($message)) { // Test log level $logLevels = array(LOG_EMERG=>'EMERG', LOG_ALERT=>'ALERT', LOG_CRIT=>'CRITICAL', LOG_ERR=>'ERR', LOG_WARNING=>'WARN', LOG_NOTICE=>'NOTICE', LOG_INFO=>'INFO', LOG_DEBUG=>'DEBUG'); - $defaultLogLevel = getDolGlobalInt('DEFAULT_SYSLOG_LEVEL', $logLevels[LOG_ERR]); if (!array_key_exists($level, $logLevels)) { - dol_syslog('The given log level does not correspond to any of the available levels: '.$level, LOG_ERR); - $level = $defaultLogLevel; + dol_syslog($langs->trans('ErrorBadLogLevel', $level), LOG_ERR); + $level = getDolGlobalInt('DEFAULT_SYSLOG_LEVEL', $logLevels[LOG_ERR]); } if ($level > $conf->global->SYSLOG_LEVEL) { return; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 046809b9405..ccc5bc87eea 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -155,6 +155,7 @@ ErrorPHPNeedModule=Error, your PHP must have module %s installed to use t ErrorOpenIDSetupNotComplete=You setup Dolibarr config file to allow OpenID authentication, but URL of OpenID service is not defined into constant %s ErrorWarehouseMustDiffers=Source and target warehouses must differs ErrorBadFormat=Bad format! +ErrorBadLogLevel=The given log level does not correspond to any of the available levels: %s ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst=Error, this member is not yet linked to any third party. Link member to an existing third party or create a new third party before creating subscription with invoice. ErrorThereIsSomeDeliveries=Error, there is some deliveries linked to this shipment. Deletion refused. ErrorCantDeletePaymentReconciliated=Can't delete a payment that had generated a bank entry that was reconciled From 6aee2db1d4d344f7e498964c44dfbd44650e0a5e Mon Sep 17 00:00:00 2001 From: Etienne BENDER Date: Tue, 17 Dec 2024 09:01:04 +0100 Subject: [PATCH 3/5] Remove use of getDolGlobalInt() --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 19839800a7a..b876186836b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1661,7 +1661,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = if (!array_key_exists($level, $logLevels)) { dol_syslog($langs->trans('ErrorBadLogLevel', $level), LOG_ERR); - $level = getDolGlobalInt('DEFAULT_SYSLOG_LEVEL', $logLevels[LOG_ERR]); + $level = $logLevels[LOG_ERR]; } if ($level > $conf->global->SYSLOG_LEVEL) { return; From be95c92c45814ac0e73dad46b70ac0ef5f8cd294 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Dec 2024 18:07:02 +0100 Subject: [PATCH 4/5] Update functions.lib.php --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b876186836b..7fe94ff83c4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1627,7 +1627,7 @@ function dol_ucwords($string, $encoding = "UTF-8") */ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = '', $restricttologhandler = '', $logcontext = null) { - global $conf, $user, $debugbar, $langs; + global $conf, $user, $debugbar; // If syslog module enabled if (empty($conf->syslog->enabled)) { @@ -1660,7 +1660,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = $logLevels = array(LOG_EMERG=>'EMERG', LOG_ALERT=>'ALERT', LOG_CRIT=>'CRITICAL', LOG_ERR=>'ERR', LOG_WARNING=>'WARN', LOG_NOTICE=>'NOTICE', LOG_INFO=>'INFO', LOG_DEBUG=>'DEBUG'); if (!array_key_exists($level, $logLevels)) { - dol_syslog($langs->trans('ErrorBadLogLevel', $level), LOG_ERR); + dol_syslog('Error Bad Log Level '.$level, LOG_ERR); $level = $logLevels[LOG_ERR]; } if ($level > $conf->global->SYSLOG_LEVEL) { From fedcec58a67614ba6619ededae1916a9b5572a0e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Dec 2024 18:09:50 +0100 Subject: [PATCH 5/5] Update errors.lang --- htdocs/langs/en_US/errors.lang | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index ccc5bc87eea..046809b9405 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -155,7 +155,6 @@ ErrorPHPNeedModule=Error, your PHP must have module %s installed to use t ErrorOpenIDSetupNotComplete=You setup Dolibarr config file to allow OpenID authentication, but URL of OpenID service is not defined into constant %s ErrorWarehouseMustDiffers=Source and target warehouses must differs ErrorBadFormat=Bad format! -ErrorBadLogLevel=The given log level does not correspond to any of the available levels: %s ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst=Error, this member is not yet linked to any third party. Link member to an existing third party or create a new third party before creating subscription with invoice. ErrorThereIsSomeDeliveries=Error, there is some deliveries linked to this shipment. Deletion refused. ErrorCantDeletePaymentReconciliated=Can't delete a payment that had generated a bank entry that was reconciled