1
0
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:
Jeremy Kitchen
2013-02-12 13:28:14 -08:00
parent 87781ebcb4
commit e987508d06

View File

@@ -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)
{ {
$this->redisClient->rpush($this->redisKey, $record["formatted"]); if ($this->redisClient instanceof \Predis\Client) {
$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();
} }
} }