Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Aug 11, 2022
1 parent ba11cb8 commit a65589e
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 167 deletions.
3 changes: 1 addition & 2 deletions Block/Adminhtml/System/Config/Form/Field/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@

class Type extends AbstractFieldArray
{
protected function _construct()
protected function _prepareToRender(): void
{
$this->addColumn('custom_logger_key', ['label' => __('Logger key')]);
$this->addColumn('custom_logger_value', ['label' => __('Logger value')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
parent::_construct();
}
}
17 changes: 0 additions & 17 deletions Config/Config.php

This file was deleted.

48 changes: 0 additions & 48 deletions Config/CustomConfiguration.php

This file was deleted.

7 changes: 2 additions & 5 deletions Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ public function __construct(
*/
public function getInstance(): HandlerInterface
{
return new StreamHandler(
'php://stdout',
$this->scopeConfig->getValue($this->levelPath)
);
return new StreamHandler('php://stdout', $this->scopeConfig->getValue($this->levelPath));
}

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
return $this->scopeConfig->isSetFlag($this->isEnabled);
}
}
2 changes: 1 addition & 1 deletion Handler/GelfHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public function getInstance(): HandlerInterface

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
return $this->scopeConfig->isSetFlag($this->isEnabled);
}
}
2 changes: 1 addition & 1 deletion Handler/MailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public function getInstance(): HandlerInterface

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
return $this->scopeConfig->isSetFlag($this->isEnabled);
}
}
4 changes: 2 additions & 2 deletions Handler/RotatingFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public function getInstance(): HandlerInterface

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
return $this->scopeConfig->isSetFlag($this->isEnabled);
}
}
}
2 changes: 1 addition & 1 deletion Handler/SlackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ public function getInstance(): HandlerInterface

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
return $this->scopeConfig->isSetFlag($this->isEnabled);
}
}
5 changes: 3 additions & 2 deletions Plugin/MonologPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Opengento\Logger\Plugin;

use Magento\Framework\Logger\Monolog;
Expand All @@ -18,8 +20,7 @@ public function aroundSetHandlers(Monolog $subject, callable $proceed, array $ha
foreach ($handlers as $handler) {
if ($handler instanceof MagentoHandlerInterface && $handler->isEnabled()) {
$magentoHandlers[] = $handler->getInstance();
}
if ($handler instanceof HandlerInterface) {
} elseif ($handler instanceof HandlerInterface) {
$magentoHandlers[] = $handler;
}
}
Expand Down
34 changes: 21 additions & 13 deletions Processor/CustomContextProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,42 @@

namespace Opengento\Logger\Processor;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Model\ScopeInterface;
use Monolog\Processor\ProcessorInterface;
use Opengento\Logger\Config\Config;
use Opengento\Logger\Config\CustomConfiguration;

class CustomContextProcessor implements ProcessorInterface
{
/**
* @var CustomConfiguration
* @var ScopeConfigInterface
*/
private $customConfiguration;
private $scopeConfig;

public function __construct(CustomConfiguration $customConfiguration)
/**
* @var Json
*/
private $serializer;

public function __construct(ScopeConfigInterface $scopeConfig, Json $serializer)
{
$this->customConfiguration = $customConfiguration;
$this->scopeConfig = $scopeConfig;
$this->serializer = $serializer;
}

public function __invoke(array $records): array
{
$customConfiguration = $this->customConfiguration->getUnserializedConfigValue(Config::CONFIG_LOGGER_CUSTOM_CONFIGURATION);

if (!$customConfiguration) {
return $records;
}

foreach ($customConfiguration as $value) {
foreach ($this->resolveTypesLogger() as $value) {
$records['context'][$value['custom_logger_key']] = $value['custom_logger_value'];
}

return $records;
}

private function resolveTypesLogger(?string $store = null): array
{
return $this->serializer->unserialize(
$this->scopeConfig->getValue('loggin/context/types_logger', ScopeInterface::SCOPE_STORE, $store) ?: '{}'
);
}
}
2 changes: 1 addition & 1 deletion Transport/UdpTransportWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function send(Message $message): int

private function createTransporter(): UdpTransport
{
return $this->transporter = $this->transportFactory->create([
return $this->transportFactory->create([
'host' => $this->scopeConfig->getValue($this->hostPath),
'port' => $this->scopeConfig->getValue($this->portPath),
'chunkSize' => $this->chunkSize
Expand Down
Loading

0 comments on commit a65589e

Please sign in to comment.