-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from avto-dev/add-logstash-udp
Add logstash udp
- Loading branch information
Showing
17 changed files
with
602 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace AvtoDev\EventsLogLaravel\Logging; | ||
|
||
use Exception; | ||
use Monolog\Logger; | ||
use InvalidArgumentException; | ||
use Monolog\Formatter\LogstashFormatter; | ||
use AvtoDev\EventsLogLaravel\Contracts\LoggerContract; | ||
use AvtoDev\EventsLogLaravel\Logging\Formatters\DefaultLogstashFormatter; | ||
|
||
class DefaultUdpLogstashLogger implements LoggerContract | ||
{ | ||
use Traits\AppNameTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws Exception | ||
*/ | ||
public function __invoke(array $config): Logger | ||
{ | ||
if (! isset($config['host'], $config['port'])) { | ||
throw new InvalidArgumentException('[host] and [port] values are required for this logger'); | ||
} | ||
|
||
$formatter = new DefaultLogstashFormatter( | ||
$config['formatter']['app_name'] ?? $this->getAppName() ?? 'app', | ||
$config['formatter']['system_name'] ?? null, | ||
$config['formatter']['extra_prefix'] ?? false, | ||
$config['formatter']['context_prefix'] ?? null, | ||
$config['formatter']['version'] ?? LogstashFormatter::V1 | ||
); | ||
|
||
$handler = new Handlers\UdpHandler( | ||
(string) $config['host'], | ||
(int) $config['port'], | ||
Logger::toMonologLevel($config['level'] ?? Logger::DEBUG), // The minimum logging level | ||
(bool) ($config['bubble'] ?? true), // Whether the messages that are handled can bubble up the stack or not | ||
(bool) ($config['silent'] ?? true) | ||
); | ||
|
||
return (new Logger($config['name'] ?? app()->environment())) | ||
->pushHandler($handler->setFormatter($formatter)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace AvtoDev\EventsLogLaravel\Logging; | ||
|
||
use Exception; | ||
use Monolog\Logger; | ||
use InvalidArgumentException; | ||
use Monolog\Formatter\LogstashFormatter; | ||
use AvtoDev\EventsLogLaravel\Contracts\LoggerContract; | ||
use AvtoDev\EventsLogLaravel\Logging\Formatters\EventsLogstashFormatter; | ||
|
||
class EventsUdpLogstashLogger implements LoggerContract | ||
{ | ||
use Traits\AppNameTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws Exception | ||
*/ | ||
public function __invoke(array $config): Logger | ||
{ | ||
if (! isset($config['host'], $config['port'])) { | ||
throw new InvalidArgumentException('[host] and [port] values are required for this logger'); | ||
} | ||
|
||
$formatter = new EventsLogstashFormatter( | ||
$config['formatter']['app_name'] ?? $this->getAppName() ?? 'app', | ||
$config['formatter']['system_name'] ?? null, | ||
$config['formatter']['extra_prefix'] ?? false, | ||
$config['formatter']['context_prefix'] ?? null, | ||
$config['formatter']['version'] ?? LogstashFormatter::V1 | ||
); | ||
|
||
$handler = new Handlers\UdpHandler( | ||
(string) $config['host'], | ||
(int) $config['port'], | ||
Logger::toMonologLevel($config['level'] ?? Logger::DEBUG), // The minimum logging level | ||
(bool) ($config['bubble'] ?? true), // Whether the messages that are handled can bubble up the stack or not | ||
(bool) ($config['silent'] ?? true) | ||
); | ||
|
||
return (new Logger($config['name'] ?? app()->environment())) | ||
->pushHandler($handler->setFormatter($formatter)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.