Skip to content

Commit

Permalink
Add enable field
Browse files Browse the repository at this point in the history
  • Loading branch information
ydup788 committed Dec 13, 2019
1 parent c6039ac commit 6ed764c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
25 changes: 24 additions & 1 deletion Transport/UdpTransportWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ class UdpTransportWrapper implements TransportInterface
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var string
*/
private $hostPath;

/**
* @var string
*/
private $portPath;

/**
* @var string
*/
private $isEnable;

/**
* @var string
*/
private $chunkSize;

/**
* @var UdpTransport
*/
Expand All @@ -45,16 +54,28 @@ class UdpTransportWrapper implements TransportInterface
*/
private $transportFactory;

/**
* UdpTransportWrapper constructor.
*
* @param UdpTransportFactory $transportFactory
* @param ScopeConfigInterface $scopeConfig
* @param string $hostPath
* @param string $portPath
* @param string $isEnable
* @param string $chunkSize
*/
public function __construct(
UdpTransportFactory $transportFactory,
ScopeConfigInterface $scopeConfig,
string $hostPath,
string $portPath,
string $isEnable,
string $chunkSize = UdpTransport::CHUNK_SIZE_LAN
) {
$this->scopeConfig = $scopeConfig;
$this->hostPath = $hostPath;
$this->portPath = $portPath;
$this->isEnable = $isEnable;
$this->chunkSize = $chunkSize;
$this->transportFactory = $transportFactory;
}
Expand All @@ -68,7 +89,9 @@ public function __construct(
*/
public function send(Message $message)
{
return $this->getTransporter()->send($message);
if ($this->scopeConfig->getValue($this->isEnable) === '1') {
return $this->getTransporter()->send($message);
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
<resource>Opengento_Logger::config_opengento_looger</resource>
<group id="loggin" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
<label>loggin</label>
<field id="is_enable" showInDefault="1" showInStore="0" showInWebsite="0" sortOrder="5" translate="label" type="select">
<label>Enable ?</label>
<comment/>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="transport_host" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="text">
<label>Gelf transport host</label>
<comment/>
</field>
<field id="transport_port" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="text">
<field id="transport_port" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="15" translate="label" type="text">
<label>Gelf transport port</label>
<comment/>
</field>
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<arguments>
<argument name="hostPath" xsi:type="string">loggin/loggin/transport_host</argument>
<argument name="portPath" xsi:type="string">loggin/loggin/transport_port</argument>
<argument name="isEnable" xsi:type="string">loggin/loggin/is_enable</argument>
</arguments>
</virtualType>

Expand Down

0 comments on commit 6ed764c

Please sign in to comment.