mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 13:16:39 +02:00
\Redis support and LineFormatter as default
per #161, this adds support for \Redis as well as switches the defaultFormatter out to use LineFormatter instead.
This commit is contained in:
@@ -12,8 +12,7 @@
|
|||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Formatter\LogstashFormatter;
|
use Monolog\Formatter\LineFormatter;
|
||||||
use Predis\Client;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs to a Redis key using rpush
|
* Logs to a Redis key using rpush
|
||||||
@@ -34,8 +33,8 @@ class RedisHandler extends AbstractProcessingHandler
|
|||||||
# redis instance, key to use
|
# redis instance, key to use
|
||||||
public function __construct($redis, $key, $level = Logger::DEBUG, $bubble = true)
|
public function __construct($redis, $key, $level = Logger::DEBUG, $bubble = true)
|
||||||
{
|
{
|
||||||
if (!($redis instanceof Client)) {
|
if (!(($redis instanceof \Predis\Client) || ($redis instanceof \Redis))) {
|
||||||
throw new \InvalidArgumentException('Predis\Client instance required');
|
throw new \InvalidArgumentException('Predis\Client or Redis instance required');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redisClient = $redis;
|
$this->redisClient = $redis;
|
||||||
@@ -46,7 +45,11 @@ class RedisHandler extends AbstractProcessingHandler
|
|||||||
|
|
||||||
protected function write(array $record)
|
protected function write(array $record)
|
||||||
{
|
{
|
||||||
|
if ($this->redisClient instanceof \Predis\Client) {
|
||||||
$this->redisClient->rpush($this->redisKey, $record["formatted"]);
|
$this->redisClient->rpush($this->redisKey, $record["formatted"]);
|
||||||
|
} else {
|
||||||
|
$this->redisClient->rPush($this->redisKey, $record["formatted"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,6 +57,6 @@ class RedisHandler extends AbstractProcessingHandler
|
|||||||
*/
|
*/
|
||||||
protected function getDefaultFormatter()
|
protected function getDefaultFormatter()
|
||||||
{
|
{
|
||||||
return new LogstashFormatter();
|
return new LineFormatter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user