diff --git a/Block/Adminhtml/System/Config/Form/Field/Type.php b/Block/Adminhtml/System/Config/Form/Field/Type.php
new file mode 100644
index 0000000..4fdecac
--- /dev/null
+++ b/Block/Adminhtml/System/Config/Form/Field/Type.php
@@ -0,0 +1,40 @@
+_elementFactory = $elementFactory;
+ parent::__construct($context, $data);
+ }
+
+ /**
+ * Initialise form fields
+ *
+ * @return void
+ */
+ protected function _construct()
+ {
+ $this->addColumn('custom_logger_key', ['label' => __('Logger key')]);
+ $this->addColumn('custom_logger_value', ['label' => __('Logger value')]);
+ $this->_addAfter = false;
+ $this->_addButtonLabel = __('Add');
+ parent::_construct();
+ }
+}
diff --git a/Config/Config.php b/Config/Config.php
new file mode 100644
index 0000000..4de753b
--- /dev/null
+++ b/Config/Config.php
@@ -0,0 +1,15 @@
+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){
+ $value = $this->getConfigValue($configPath, $store);
+
+ if(!$value) return false;
+
+ return $this->serializer->unserialize($value);
+ }
+}
\ No newline at end of file
diff --git a/Publisher/GelfPublisherWrapper.php b/Publisher/GelfPublisherWrapper.php
index afcc5f8..55d5298 100644
--- a/Publisher/GelfPublisherWrapper.php
+++ b/Publisher/GelfPublisherWrapper.php
@@ -3,10 +3,13 @@
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
+
namespace Opengento\Logger\Publisher;
use Gelf\MessageInterface;
use Gelf\PublisherInterface;
+use Opengento\Logger\Config\CustomConfiguration;
+use Opengento\Logger\Config\Config;
/**
* Class GelfPublisherWrapper
@@ -20,8 +23,19 @@ class GelfPublisherWrapper implements PublisherInterface
*/
private $publisher;
- public function __construct(PublisherInterface $publisher)
+ /**
+ * @var CustomConfiguration
+ */
+ private $customConfiguration;
+
+ /**
+ * GelfPublisherWrapper constructor.
+ * @param PublisherInterface $publisher
+ * @param CustomConfiguration $customConfiguration
+ */
+ public function __construct(PublisherInterface $publisher, CustomConfiguration $customConfiguration)
{
+ $this->customConfiguration = $customConfiguration;
$this->publisher = $publisher;
}
@@ -34,6 +48,22 @@ public function __construct(PublisherInterface $publisher)
*/
public function publish(MessageInterface $message)
{
+ $this->joinCustomConfiguration($message);
+
return $this->publisher->publish($message);
}
+
+ /**
+ * @param MessageInterface $message
+ */
+ public function joinCustomConfiguration(MessageInterface $message)
+ {
+ $customConfiguration = $this->customConfiguration->getUnserializedConfigValue(Config::CONFIG_LOGGER_CUSTOM_CONFIGURATION);
+
+ if(!$customConfiguration) return;
+
+ foreach ($customConfiguration as $value) {
+ $message->setAdditional($value['custom_logger_key'], $value['custom_logger_value']);
+ }
+ }
}
diff --git a/composer.json b/composer.json
index 0246278..47acc33 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,7 @@
"graylog2/gelf-php": "^1.6"
},
"type": "magento2-module",
- "version": "0.1.0",
+ "version": "0.2.0",
"license": [
"MIT"
],
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index a7ff1b3..92f8147 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -29,6 +29,12 @@
+
+
+ Opengento\Logger\Block\Adminhtml\System\Config\Form\Field\Type
+ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized
+ Add key with custom value
+
diff --git a/etc/di.xml b/etc/di.xml
index 7768da4..b587a21 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -21,9 +21,15 @@
-
+
gelfPublisher
+
+
+
+
+
+ gelfPublisherWrapper
Monolog\Logger::INFO
diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv
new file mode 100644
index 0000000..407650c
--- /dev/null
+++ b/i18n/fr_FR.csv
@@ -0,0 +1,7 @@
+"Enable ?", "Activé ?"
+"Gelf transport host", "Gelf transport host"
+"Gelf transport port", "Gelf transport port"
+"Custom configuration", "Configuration personnalisée"
+"Add key with custom value", "Ajoute une clé avec des valeurs personnalisées"
+"Logger key", "Logger key"
+"Logger value", "Logger value"
\ No newline at end of file