ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RedisHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Handler;
13 
15 use Monolog\Logger;
16 
29 {
30  private $redisClient;
31  private $redisKey;
32  protected $capSize;
33 
41  public function __construct($redis, $key, $level = Logger::DEBUG, $bubble = true, $capSize = false)
42  {
43  if (!(($redis instanceof \Predis\Client) || ($redis instanceof \Redis))) {
44  throw new \InvalidArgumentException('Predis\Client or Redis instance required');
45  }
46 
47  $this->redisClient = $redis;
48  $this->redisKey = $key;
49  $this->capSize = $capSize;
50 
51  parent::__construct($level, $bubble);
52  }
53 
57  protected function write(array $record)
58  {
59  if ($this->capSize) {
60  $this->writeCapped($record);
61  } else {
62  $this->redisClient->rpush($this->redisKey, $record["formatted"]);
63  }
64  }
65 
73  protected function writeCapped(array $record)
74  {
75  if ($this->redisClient instanceof \Redis) {
76  $this->redisClient->multi()
77  ->rpush($this->redisKey, $record["formatted"])
78  ->ltrim($this->redisKey, -$this->capSize, -1)
79  ->exec();
80  } else {
83  $this->redisClient->transaction(function ($tx) use ($record, $redisKey, $capSize) {
84  $tx->rpush($redisKey, $record["formatted"]);
85  $tx->ltrim($redisKey, -$capSize, -1);
86  });
87  }
88  }
89 
93  protected function getDefaultFormatter()
94  {
95  return new LineFormatter();
96  }
97 }
__construct($redis, $key, $level=Logger::DEBUG, $bubble=true, $capSize=false)
const DEBUG
Detailed debug information.
Definition: Logger.php:33
Base Handler class providing the Handler structure.
Logs to a Redis key using rpush.
writeCapped(array $record)
Write and cap the collection Writes the record to the redis list and caps its.
Formats incoming records into a one-line string.
$key
Definition: croninfo.php:18