Skip to content

Commit

Permalink
Merge pull request #4 from MeCapron/feature/add_slack_logger
Browse files Browse the repository at this point in the history
Feature/add slack logger
  • Loading branch information
TonySma authored Jan 14, 2022
2 parents 2e6844e + 30f4342 commit eee9c2a
Show file tree
Hide file tree
Showing 28 changed files with 888 additions and 225 deletions.
35 changes: 9 additions & 26 deletions Block/Adminhtml/System/Config/Form/Field/Type.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

namespace Opengento\Logger\Block\Adminhtml\System\Config\Form\Field;

class Type extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
declare(strict_types=1);

/**
* @var \Magento\Framework\Data\Form\Element\Factory
*/
protected $_elementFactory;
namespace Opengento\Logger\Block\Adminhtml\System\Config\Form\Field;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Data\Form\Element\Factory $elementFactory,
array $data = []
) {
$this->_elementFactory = $elementFactory;
parent::__construct($context, $data);
}
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;

/**
* Initialise form fields
*
* @return void
*/
class Type extends AbstractFieldArray
{
protected function _construct()
{
$this->addColumn('custom_logger_key', ['label' => __('Logger key')]);
Expand Down
16 changes: 9 additions & 7 deletions Config/Config.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

declare(strict_types=1);

namespace Opengento\Logger\Config;

use \Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\AbstractHelper;

/**
* Class Config
* @package Opengento\Logger\Config
*/
class Config extends AbstractHelper
{
/** Config keys */
const CONFIG_LOGGER_CUSTOM_CONFIGURATION = 'loggin/loggin/types_logger';
}
public const CONFIG_LOGGER_CUSTOM_CONFIGURATION = 'loggin/context/types_logger';
}
57 changes: 24 additions & 33 deletions Config/CustomConfiguration.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,48 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

declare(strict_types=1);

namespace Opengento\Logger\Config;

/**
* Class CustomConfiguration
*/
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Model\ScopeInterface;

class CustomConfiguration
{
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
* @var Json
*/
private $serializer;


/**
* CustomFields constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
*/
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Serialize\Serializer\Json $serializer)
public function __construct(ScopeConfigInterface $scopeConfig, Json $serializer)
{
$this->scopeConfig = $scopeConfig;
$this->serializer = $serializer;
}

/**
* @param $configPath
* @param null $store
* @return mixed
*/
public function getConfigValue($configPath, $store = null){
return $this->scopeConfig->getValue(
$configPath,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* @param $configPath
* @param null $store
* @return array|bool|float|int|mixed|string|null
*/
public function getUnserializedConfigValue($configPath, $store = null){
public function getUnserializedConfigValue(string $configPath, ?string $store = null): ?array
{
$value = $this->getConfigValue($configPath, $store);

if(!$value) return false;
if (!$value) {
return null;
}

return $this->serializer->unserialize($value);
}
}

public function getConfigValue(string $configPath, ?string $store = null)
{
return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $store);
}
}
29 changes: 29 additions & 0 deletions Config/Source/LoggingLevel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

declare(strict_types=1);

namespace Opengento\Logger\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;
use Monolog\Logger;

class LoggingLevel implements OptionSourceInterface
{
public function toOptionArray(): array
{
return [
['value' => Logger::DEBUG, 'label' => __('Debug')],
['value' => Logger::INFO, 'label' => __('Info')],
['value' => Logger::NOTICE, 'label' => __('Notice')],
['value' => Logger::WARNING, 'label' => __('Warning')],
['value' => Logger::ERROR, 'label' => __('Error')],
['value' => Logger::CRITICAL, 'label' => __('Critical')],
['value' => Logger::ALERT, 'label' => __('Alert')],
['value' => Logger::EMERGENCY, 'label' => __('Emergency')],
];
}
}
58 changes: 58 additions & 0 deletions Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

declare(strict_types=1);

namespace Opengento\Logger\Handler;

use Exception;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Monolog\Handler\HandlerInterface;
use Monolog\Handler\StreamHandler;

class ConsoleHandler implements MagentoHandlerInterface
{
/**
* @var string
*/
private $isEnabled;

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

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

public function __construct(
ScopeConfigInterface $scopeConfig,
string $isEnabled,
string $levelPath
) {
$this->scopeConfig = $scopeConfig;
$this->isEnabled = $isEnabled;
$this->levelPath = $levelPath;
}

/**
* @throws Exception
*/
public function getInstance(): HandlerInterface
{
return new StreamHandler(
'php://stdout',
$this->scopeConfig->getValue($this->levelPath)
);
}

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
}
}
62 changes: 62 additions & 0 deletions Handler/GelfHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

declare(strict_types=1);

namespace Opengento\Logger\Handler;

use Gelf\PublisherInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Monolog\Handler\GelfHandler as MonologGelfHandler;
use Monolog\Handler\HandlerInterface;

class GelfHandler implements MagentoHandlerInterface
{
/**
* @var PublisherInterface
*/
private $publisher;

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

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

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

public function __construct(
PublisherInterface $publisher,
ScopeConfigInterface $scopeConfig,
string $isEnabled,
string $levelPath
) {
$this->publisher = $publisher;
$this->isEnabled = $isEnabled;
$this->levelPath = $levelPath;
$this->scopeConfig = $scopeConfig;
}

public function getInstance(): HandlerInterface
{
return new MonologGelfHandler(
$this->publisher,
$this->scopeConfig->getValue($this->levelPath)
);
}

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue($this->isEnabled);
}
}
32 changes: 0 additions & 32 deletions Handler/GelfHandlerWrapper.php

This file was deleted.

18 changes: 18 additions & 0 deletions Handler/MagentoHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/

declare(strict_types=1);

namespace Opengento\Logger\Handler;

use Monolog\Handler\HandlerInterface;

interface MagentoHandlerInterface
{
public function getInstance(): HandlerInterface;

public function isEnabled(): bool;
}
Loading

0 comments on commit eee9c2a

Please sign in to comment.