Skip to content

Commit fab3f1e

Browse files
committed
new log data
1 parent 6bf4161 commit fab3f1e

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

Logger/Logger.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@
77

88
use Graycore\GraphQlLogger\Api\LogRepositoryInterface;
99
use Graycore\GraphQlLogger\Api\Data\LogInterfaceFactory as LogFactory;
10-
use Magento\Framework\App\RequestInterface;
1110
use Magento\Framework\Exception\NoSuchEntityException;
1211
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1312

1413
class Logger implements LoggerInterface
1514
{
1615
private LogRepositoryInterface $logRepository;
1716
private LogFactory $logFactory;
18-
private RequestInterface $request;
1917
private TimezoneInterface $date;
2018
private Config $config;
2119

2220
/**
2321
* @param Config $config
2422
*/
2523
public function __construct(
26-
RequestInterface $request,
2724
LogRepositoryInterface $logRepository,
2825
LogFactory $logFactory,
2926
TimezoneInterface $date,
@@ -54,7 +51,7 @@ public function execute(array $queryDetails)
5451
}
5552

5653
$log->setHash($hash)
57-
->setMethod($this->request->getMethod())
54+
->setMethod($queryDetails[LoggerInterface::HTTP_METHOD])
5855
->setQuery($queryDetails['query'])
5956
->setUpdated($this->date->date()->format('Y-m-d H:i:s'));
6057
$this->logRepository->save($log);

Plugin/LogDataPlugin.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Graycore\GraphQlLogger\Logger;
4+
5+
use Graycore\GraphQlLogger\Model\Config;
6+
use Magento\Framework\App\RequestInterface;
7+
use Magento\GraphQl\Helper\Query\Logger\LogData;
8+
9+
class LogDataPlugin
10+
{
11+
private Config $config;
12+
13+
/**
14+
* @param Config $config
15+
*/
16+
public function __construct(
17+
Config $config
18+
) {
19+
$this->config = $config;
20+
}
21+
22+
public function afterGetLogData(
23+
LogData $logdata,
24+
array $result,
25+
RequestInterface $request,
26+
array $data
27+
): array {
28+
if (!$this->config->isEnabled()) {
29+
return $result;
30+
}
31+
32+
/**
33+
* Add the query to the data.
34+
*/
35+
$result['query'] = $data['query'];
36+
return $result;
37+
}
38+
}

etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
</argument>
1111
</arguments>
1212
</type>
13+
<type name="Magento\GraphQl\Helper\Query\Logger\LogData">
14+
<plugin name="Graycore_GraphQlLogger::additionalLogData" type="Graycore\GraphQlLogger\Plugin\LogDataPlugin"/>
15+
</type>
1316
</config>

0 commit comments

Comments
 (0)