Skip to content

Commit 6eacbed

Browse files
authored
Merge pull request #1 from igorwulff/igorwulff-patch-2
Added option to disable ajax calls from being logged.
2 parents 98ecade + c05fb47 commit 6eacbed

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

Model/Config.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Config
1818
*/
1919
protected const WEBAPI_LOGS_IS_ENABLED_CONFIG_PATH = 'webapi_logs/log/enabled';
2020

21+
22+
protected const WEBAPI_LOGS_DISABLED_AJAX_CALLS = 'webapi_logs/log/disable_ajax_calls';
2123
/**
2224
* string
2325
*/
@@ -58,6 +60,15 @@ public function isEnabled(): bool
5860
);
5961
}
6062

63+
public function isAjaxCallsDisabled(): bool
64+
{
65+
return $this->scopeConfig->isSetFlag(
66+
self::WEBAPI_LOGS_DISABLED_AJAX_CALLS,
67+
ScopeInterface::SCOPE_WEBSITE
68+
);
69+
}
70+
71+
6172
/**
6273
* @return bool
6374
*/

Plugin/FrontControllerDispatchAfter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public function __construct(
5454
*/
5555
public function afterDispatch(Rest $subject, $result, RequestInterface $request)
5656
{
57-
if ($this->config->isEnabled()) {
57+
if ($this->config->isEnabled()
58+
&& (
59+
!$request->isXmlHttpRequest()
60+
|| !$this->config->isAjaxCallsDisabled()
61+
)
62+
) {
5863
$exceptions = $result->getException();
5964

6065
if (!empty($exceptions)) {

Plugin/FrontControllerDispatchBefore.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ public function __construct(
5353
*/
5454
public function beforeDispatch(Rest $subject, RequestInterface $request)
5555
{
56-
if ($this->config->isEnabled()) {
56+
if ($this->config->isEnabled()
57+
&& (
58+
!$request->isXmlHttpRequest()
59+
|| !$this->config->isAjaxCallsDisabled()
60+
)
61+
) {
5762
$requestMethod = $request->getMethod();
5863
$requestorIp = $request->getClientIp();
5964
$requestPath = $request->getUriString();

etc/adminhtml/system.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<label>Enable Webapi Logs</label>
1818
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1919
</field>
20+
<field id="disable_ajax_calls" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
21+
<label>Disable Webapi logs for AJAX calls</label>
22+
<comment><![CDATA[Ajax calls are used in cases of the checkout for example]]></comment>
23+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
24+
</field>
2025
<field id="secret_mode" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
2126
<label>Enable Secret Mode</label>
2227
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>

0 commit comments

Comments
 (0)