diff --git a/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php b/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php index f182f43b2..d6da764c7 100644 --- a/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php +++ b/src/module-elasticsuite-core/Api/Client/ClientConfigurationInterface.php @@ -30,6 +30,13 @@ interface ClientConfigurationInterface */ public function getServerList(); + /** + * Indicates whether the body of requests in error should be logged or not. + * + * @return boolean + */ + public function isLoggingErrorRequest(); + /** * Indicates whether the debug node is enabled or not. * diff --git a/src/module-elasticsuite-core/Client/Client.php b/src/module-elasticsuite-core/Client/Client.php index f93459fef..1e5ca8a84 100644 --- a/src/module-elasticsuite-core/Client/Client.php +++ b/src/module-elasticsuite-core/Client/Client.php @@ -219,8 +219,7 @@ public function search($params) try { $response = $this->getEsClient()->search($params); } catch (\Exception $e) { - // If debug is enabled, no need to log, the ES client would already have done it. - if (false === $this->clientConfiguration->isDebugModeEnabled()) { + if ($this->clientConfiguration->isLoggingErrorRequest()) { $requestInfo = json_encode($params, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE); $this->logger->error(sprintf("Search Request Failure [error] : %s", $e->getMessage())); $this->logger->error(sprintf("Search Request Failure [request] : %s", $requestInfo)); diff --git a/src/module-elasticsuite-core/Client/ClientConfiguration.php b/src/module-elasticsuite-core/Client/ClientConfiguration.php index 50c332df5..0ba2fabee 100644 --- a/src/module-elasticsuite-core/Client/ClientConfiguration.php +++ b/src/module-elasticsuite-core/Client/ClientConfiguration.php @@ -54,6 +54,14 @@ public function getServerList() return explode(',', $this->getElasticsearchClientConfigParam('servers') ?? ''); } + /** + * {@inheritDoc} + */ + public function isLoggingErrorRequest() + { + return (bool) $this->getElasticsearchClientConfigParam('enable_error_request_logging'); + } + /** * {@inheritdoc} */ diff --git a/src/module-elasticsuite-core/etc/adminhtml/system.xml b/src/module-elasticsuite-core/etc/adminhtml/system.xml index e5aeab176..b4e18aaca 100644 --- a/src/module-elasticsuite-core/etc/adminhtml/system.xml +++ b/src/module-elasticsuite-core/etc/adminhtml/system.xml @@ -30,53 +30,58 @@ - + List of servers in [host]:[port] format separated by a comma (e.g. : "es-node1.fqdn:9200, es-node2.fqdn:9200") - + Select yes if you want to connect to your Elasticsearch server over HTTPS. Magento\Config\Model\Config\Source\Yesno - + Select no if you are using self-signed SSL certificate. Magento\Config\Model\Config\Source\Yesno - + Enable this option when your Elasticsearch server use basic HTTP authentication. Magento\Config\Model\Config\Source\Yesno - + Enable this option when you want to base64 encode the Authorization headers. (Open Distro requires this) Magento\Config\Model\Config\Source\Yesno - + 1 - + 1 - + + + + Magento\Config\Model\Config\Source\Yesno + + When enabled the module will produce logs through Magento logging system. Magento\Config\Model\Config\Source\Yesno - + In seconds. validate-number - + Maximum number of times to retry connection when there is a connection failure validate-number diff --git a/src/module-elasticsuite-core/etc/config.xml b/src/module-elasticsuite-core/etc/config.xml index cbebaa6ed..5b38454d7 100644 --- a/src/module-elasticsuite-core/etc/config.xml +++ b/src/module-elasticsuite-core/etc/config.xml @@ -19,6 +19,7 @@ + 0 0 localhost:9200 1 diff --git a/src/module-elasticsuite-core/i18n/en_US.csv b/src/module-elasticsuite-core/i18n/en_US.csv index 3c35ff94d..514bf1f7c 100644 --- a/src/module-elasticsuite-core/i18n/en_US.csv +++ b/src/module-elasticsuite-core/i18n/en_US.csv @@ -53,6 +53,8 @@ General,General "Basic HTTP authentication password","Basic HTTP authentication password" "Enable Debug Mode","Enable Debug Mode" "When enabled the module will produce logs through Magento logging system.","When enabled the module will produce logs through Magento logging system." +"Enable logging of request that produce errors","Enable logging of request that produce errors" +"This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled.","This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled." "Server Connection Timeout","Server Connection Timeout" "In seconds.","In seconds." "Indices Settings","Indices Settings" diff --git a/src/module-elasticsuite-core/i18n/fr_FR.csv b/src/module-elasticsuite-core/i18n/fr_FR.csv index 8b2fe1b43..71547b973 100644 --- a/src/module-elasticsuite-core/i18n/fr_FR.csv +++ b/src/module-elasticsuite-core/i18n/fr_FR.csv @@ -53,6 +53,8 @@ General,Général "Basic HTTP authentication password","Mot de passe pour l'authentification HTTP" "Enable Debug Mode","Activer le mode debug" "When enabled the module will produce logs through Magento logging system.","Lorsqu'activé, le module va produire des logs via le système de logs Magento standard." +"Enable logging of request that produce errors","Journaliser les requêtes en erreur" +"This is an alternative to the debug mode for production environments. If enabled, even when the debug mode is disabled, the body of search requests that produce an error will be logged. If disabled, only the error message/exception message will be logged (legacy behavior). A log rotation system on the var/log/system.log file is advised if enabled.","Ceci est une alternative au mode debug pour les environnements de production. Lorsqu'activé, même si le mode debug est désactivé, le corps des requêtes en erreur sera loggé. Si désactivé, seul l'exception/le message d'erreur sera loggé (comportement historique). Un système de rotation des logs sur le fichier var/log/system.log est recommandé si activé." "Server Connection Timeout","Délai de connexion au serveur" "In seconds.","En secondes." "Indices Settings","Paramètres des index"