Skip to content

Commit

Permalink
init repository
Browse files Browse the repository at this point in the history
  • Loading branch information
David Verholen committed Jan 8, 2019
0 parents commit 943d1ee
Show file tree
Hide file tree
Showing 10 changed files with 2,782 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
/vendor
45 changes: 45 additions & 0 deletions Model/ConfiguredUdpTransport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);

namespace Brandung\GelfLogger\Model;

use Gelf\MessageInterface as Message;
use Gelf\Transport\TransportInterface;
use Gelf\Transport\UdpTransport;
use Magento\Framework\App\Config\ScopeConfigInterface;

class ConfiguredUdpTransport implements TransportInterface
{
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var UdpTransport
*/
private $udpTransport;

public function __construct(ScopeConfigInterface $scopeConfig)
{
$this->scopeConfig = $scopeConfig;
}

public function send(Message $message): ?int
{
try {
return $this->getUdpTransport()->send($message);
} catch (\Exception $e) {
return -1;
}
}

private function getUdpTransport(): UdpTransport
{
if (null === $this->udpTransport) {
$host = $this->scopeConfig->getValue('system/gelf_logger/host');
$port = $this->scopeConfig->getValue('system/gelf_logger/port');
$this->udpTransport = new UdpTransport($host, $port);
}
return $this->udpTransport;
}
}
15 changes: 15 additions & 0 deletions Model/GelfHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Brandung\GelfLogger\Model;

use Gelf\PublisherInterface;
use Monolog\Logger;

class GelfHandler extends \Monolog\Handler\GelfHandler
{
public function __construct(PublisherInterface $publisher, $level = Logger::DEBUG, $bubble = true)
{
parent::__construct($publisher, $level, $bubble);
}
}
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "brandung/magento2-gelf-logger",
"license": "MIT",
"description": "Gelf Logger Handler",
"require": {
"php": "^7.1.0",
"graylog2/gelf-php": "^1.6",
"monolog/monolog": "^1.17",
"magento/framework": "^101.0.6"
},
"type": "magento2-module",
"autoload": {
"files": [
"./registration.php"
],
"psr-4": {
"Brandung\\GelfLogger\\": ""
}
},
"repositories": {
"magento": {
"type": "composer",
"url": "https://repo.magento.com"
}
}
}
Loading

0 comments on commit 943d1ee

Please sign in to comment.