1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 00:56:08 +02:00

Allow for both mlehner/gelf-php and graylog2/gelf-php usage

This commit is contained in:
Benjamin Zikarsky
2014-02-22 16:11:33 +01:00
parent c8289fd654
commit f0ed3d8054
4 changed files with 143 additions and 5 deletions

View File

@@ -11,7 +11,9 @@
namespace Monolog\Handler;
use Gelf\Publisher;
use Gelf\IMessagePublisher;
use Gelf\PublisherInterface;
use InvalidArgumentException;
use Monolog\Logger;
use Monolog\Formatter\GelfMessageFormatter;
@@ -29,14 +31,25 @@ class GelfHandler extends AbstractProcessingHandler
protected $publisher;
/**
* @param Publisher $publisher a publisher object
* @param PublisherInterface|IMessagePublisher $publisher a publisher object
* @param integer $level The minimum logging level at which this handler will be triggered
* @param boolean $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(Publisher $publisher, $level = Logger::DEBUG, $bubble = true)
public function __construct($publisher, $level = Logger::DEBUG, $bubble = true)
{
parent::__construct($level, $bubble);
$validPublisher = false;
if (interface_exists('\Gelf\IMessagePublisher') && $publisher instanceof IMessagePublisher) {
$validPublisher = true;
} elseif (interface_exists('\Gelf\PublisherInterface') && $publisher instanceof PublisherInterface) {
$validPublisher = true;
}
if (!$validPublisher) {
throw new InvalidArgumentException("Invalid publisher");
}
$this->publisher = $publisher;
}