mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-10 07:06:40 +02:00
AMQP
This commit is contained in:
@@ -16,22 +16,24 @@ use Monolog\Formatter\JsonFormatter;
|
||||
|
||||
class AmqpHandler extends AbstractProcessingHandler
|
||||
{
|
||||
/** @var \AMQPExchange $exchange */
|
||||
protected $exchange;
|
||||
/** @var string $space */
|
||||
protected $space;
|
||||
|
||||
/**
|
||||
* @param \AMQPConnection $amqp Amqp connection, ready for use
|
||||
* @param string $exchange exchange name
|
||||
* @param \AMQPConnection $amqp AMQP connection, ready for use
|
||||
* @param string $exchangeName
|
||||
* @param string $space string to be able better manage routing keys
|
||||
* @param int $level
|
||||
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
||||
*/
|
||||
function __construct(\AMQPConnection $amqp, $exchange = 'log', $space = '', $level = Logger::DEBUG, $bubble = true)
|
||||
function __construct(\AMQPConnection $amqp, $exchangeName = 'log', $space = '', $level = Logger::DEBUG, $bubble = true)
|
||||
{
|
||||
$this->space = $space;
|
||||
$channel = new \AMQPChannel($amqp);
|
||||
$this->exchange = new \AMQPExchange($channel);
|
||||
$this->exchange->setName($exchange);
|
||||
$this->exchange->setName($exchangeName);
|
||||
parent::__construct($level, $bubble);
|
||||
}
|
||||
|
||||
|
50
tests/Monolog/Handler/AmqpHandlerTest.php
Normal file
50
tests/Monolog/Handler/AmqpHandlerTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\TestCase;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\RotatingFileHandler
|
||||
*/
|
||||
class RotatingFileHandlerTest extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('AMQPConnection') || !class_exists('AMQPExchange')) {
|
||||
$this->markTestSkipped("amqp-php not installed");
|
||||
}
|
||||
|
||||
if (!class_exists('AMQPChannel')) {
|
||||
throw new \Exception(' Please update AMQP to version >= 1');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/AmqpMocks.php';
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
// $handler = new AmqpHandler($this->getMockAMQPConnection(), 'log', 'monolog');
|
||||
}
|
||||
|
||||
public function getMockAMQPConnection() {
|
||||
return new MockAMQPConnection();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
61
tests/Monolog/Handler/AmqpMocks.php
Normal file
61
tests/Monolog/Handler/AmqpMocks.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
class MockAMQPConnection extends \AMQPConnection
|
||||
{
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public function pconnect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function reconnect()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function connect() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isConnected() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MockAMQPChannel extends \AMQPChannel
|
||||
{
|
||||
public function __construct(MockAMQPConnection $connection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class MockAMQPExchange extends \AMQPExchange
|
||||
{
|
||||
|
||||
public function __construct(MockAMQPChannel $channel) {
|
||||
|
||||
}
|
||||
|
||||
public function publish($message, $routing_key, $flags, $headers){
|
||||
return;
|
||||
}
|
||||
|
||||
public function setName($exchangeName) {
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user