mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-11 15:44:34 +02:00
Adds ability to cap log size in redis
100% backward compatible, defaults to not capping collection size. Additional constructor param of $capSize added which will ensure logs list is treated as a FILO queue Test coverage on new functionality
This commit is contained in:
@@ -68,4 +68,61 @@ class RedisHandlerTest extends TestCase
|
||||
$handler->setFormatter(new LineFormatter("%message%"));
|
||||
$handler->handle($record);
|
||||
}
|
||||
|
||||
public function testRedisHandleCapped()
|
||||
{
|
||||
$redis = $this->getMock('Redis', array('multi', 'lpush', 'ltrim', 'execute'));
|
||||
|
||||
// Redis uses multi
|
||||
$redis->expects($this->once())
|
||||
->method('multi')
|
||||
->will($this->returnSelf());
|
||||
|
||||
$redis->expects($this->once())
|
||||
->method('lpush')
|
||||
->will($this->returnSelf());
|
||||
|
||||
$redis->expects($this->once())
|
||||
->method('ltrim')
|
||||
->will($this->returnSelf());
|
||||
|
||||
$redis->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnSelf());
|
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
|
||||
|
||||
$handler = new RedisHandler($redis, 'key', Logger::DEBUG, true, 10);
|
||||
$handler->setFormatter(new LineFormatter("%message%"));
|
||||
$handler->handle($record);
|
||||
}
|
||||
|
||||
public function testPredisHandleCapped()
|
||||
{
|
||||
$redis = $this->getMock('Predis\Client', array('transaction'));
|
||||
|
||||
// Redis uses multi
|
||||
$redis->expects($this->once())
|
||||
->method('transaction')
|
||||
->will($this->returnCallback(function($cb){
|
||||
|
||||
$redisTransaction = $this->getMock('Predis\Client', array('lpush', 'ltrim'));
|
||||
|
||||
$redisTransaction->expects($this->once())
|
||||
->method('lpush')
|
||||
->will($this->returnSelf());
|
||||
|
||||
$redisTransaction->expects($this->once())
|
||||
->method('ltrim')
|
||||
->will($this->returnSelf());
|
||||
|
||||
$cb($redisTransaction);
|
||||
}));
|
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
|
||||
|
||||
$handler = new RedisHandler($redis, 'key', Logger::DEBUG, true, 10);
|
||||
$handler->setFormatter(new LineFormatter("%message%"));
|
||||
$handler->handle($record);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user