Skip to content

Commit

Permalink
Adding ignored messages configuration for gelf logger.
Browse files Browse the repository at this point in the history
Use case is that PsrFactoryDiscovery send a lot of messages in Gelf which are not real debug exceptions
  • Loading branch information
MeCapron committed Mar 24, 2022
1 parent cc52ae4 commit 33c5fa0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 6 additions & 2 deletions Handler/RotatingFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public function __construct(
public function getInstance(): HandlerInterface
{
return new \Monolog\Handler\RotatingFileHandler(
sprintf('%s/log/%s', $this->directoryList->getPath('var'), $this->scopeConfig->getValue($this->filenamePath)),
sprintf(
'%s/log/%s',
$this->directoryList->getPath(DirectoryList::VAR_DIR),
$this->scopeConfig->getValue($this->filenamePath)
),
$this->scopeConfig->getValue($this->maxFilesPath),
$this->scopeConfig->getValue($this->levelPath)
);
Expand All @@ -77,4 +81,4 @@ public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
}
}
}
Empty file removed Publisher/GelfPublisherWrapper.php
Empty file.
22 changes: 13 additions & 9 deletions Transport/UdpTransportWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Gelf\Transport\UdpTransportFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;

use in_array;

/**
* Class UdpTransportWrapper
*
Expand Down Expand Up @@ -52,26 +54,24 @@ class UdpTransportWrapper implements TransportInterface
private $transportFactory;

/**
* UdpTransportWrapper constructor.
*
* @param UdpTransportFactory $transportFactory
* @param ScopeConfigInterface $scopeConfig
* @param string $hostPath
* @param string $portPath
* @param string $chunkSize
* @var string[]
*/
private $ignoredMessages;

public function __construct(
UdpTransportFactory $transportFactory,
ScopeConfigInterface $scopeConfig,
string $hostPath,
string $portPath,
string $chunkSize = UdpTransport::CHUNK_SIZE_LAN
string $chunkSize = UdpTransport::CHUNK_SIZE_LAN,
array $ignoredMessages = []
) {
$this->scopeConfig = $scopeConfig;
$this->hostPath = $hostPath;
$this->portPath = $portPath;
$this->chunkSize = $chunkSize;
$this->transportFactory = $transportFactory;
$this->ignoredMessages = $ignoredMessages;
}

/**
Expand All @@ -83,6 +83,10 @@ public function __construct(
*/
public function send(Message $message): int
{
if (in_array($message->getShortMessage(), $this->ignoredMessages, true)) {
return 0;
}

return $this->getTransporter()->send($message);
}

Expand All @@ -101,4 +105,4 @@ private function getTransporter(): UdpTransport

return $this->transporter;
}
}
}

0 comments on commit 33c5fa0

Please sign in to comment.