Skip to content

Commit

Permalink
Merge pull request #10 from opengento/cleanup/simplify
Browse files Browse the repository at this point in the history
Fix memory leak usage
  • Loading branch information
thomas-kl1 authored Aug 13, 2022
2 parents c2ca5b8 + 46773f1 commit b701f61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
10 changes: 5 additions & 5 deletions Plugin/MonologPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

class MonologPlugin
{
public function aroundSetHandlers(Monolog $subject, callable $proceed, array $handlers): void
public function beforeSetHandlers(Monolog $subject, array $handlers): array
{
$magentoHandlers = [];
foreach ($handlers as $handler) {
foreach ($handlers as $key => $handler) {
if ($handler instanceof MagentoHandlerInterface && $handler->isEnabled()) {
$magentoHandlers[] = $handler->getInstance();
$magentoHandlers[$key] = $handler->getInstance();
} elseif ($handler instanceof HandlerInterface) {
$magentoHandlers[] = $handler;
$magentoHandlers[$key] = $handler;
}
}

$proceed($magentoHandlers);
return [$magentoHandlers];
}
}
18 changes: 6 additions & 12 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
* See LICENSE bundled with this library for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

<virtualType name="gelfTransport" type="Opengento\Logger\Transport\UdpTransportWrapper">
<virtualType name="GelfTransport" type="Opengento\Logger\Transport\UdpTransportWrapper">
<arguments>
<argument name="hostPath" xsi:type="string">loggin/gelf/transport_host</argument>
<argument name="portPath" xsi:type="string">loggin/gelf/transport_port</argument>
</arguments>
</virtualType>

<virtualType name="gelfPublisher" type="Gelf\Publisher">
<virtualType name="GelfPublisher" type="Gelf\Publisher">
<arguments>
<argument name="transport" xsi:type="object">gelfTransport</argument>
<argument name="transport" xsi:type="object">GelfTransport</argument>
</arguments>
</virtualType>

<virtualType name="GelfHandler" type="Opengento\Logger\Handler\GelfHandler">
<arguments>
<argument name="isEnabled" xsi:type="string">loggin/gelf/is_enabled</argument>
<argument name="levelPath" xsi:type="string">loggin/gelf/level</argument>
<argument name="publisher" xsi:type="object">gelfPublisher</argument>
<argument name="publisher" xsi:type="object">GelfPublisher</argument>
</arguments>
</virtualType>

Expand Down Expand Up @@ -73,13 +72,8 @@

<virtualType name="NoopHandler" type="Monolog\Handler\NullHandler"/>

<type name="Magento\Framework\Logger\Monolog">
<plugin name="override_set_handlers_method" type="Opengento\Logger\Plugin\MonologPlugin" sortOrder="1"/>
</type>

<type name="Magento\Framework\Logger\Monolog">
<arguments>
<argument name="name" xsi:type="string">main</argument>
<argument name="handlers" xsi:type="array">
<item name="gelf" xsi:type="object">GelfHandler</item>
<item name="mail" xsi:type="object">MailHandler</item>
Expand All @@ -93,6 +87,6 @@
<item name="custom_context" xsi:type="object">Opengento\Logger\Processor\CustomContextProcessor</item>
</argument>
</arguments>
<plugin name="override_set_handlers_method" type="Opengento\Logger\Plugin\MonologPlugin" sortOrder="1"/>
</type>
</config>

0 comments on commit b701f61

Please sign in to comment.