ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
12namespace Monolog\Handler;
13
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}
An exception for terminatinating execution or to throw for unit testing.
Formats incoming records into a one-line string.
Base Handler class providing the Handler structure.
Logs to a Redis key using rpush.
write(array $record)
Writes the record down to the log of the implementing handler.void
__construct($redis, $key, $level=Logger::DEBUG, $bubble=true, $capSize=false)
writeCapped(array $record)
Write and cap the collection Writes the record to the redis list and caps its.
getDefaultFormatter()
Gets the default formatter.FormatterInterface
Monolog log channel.
Definition: Logger.php:28
const DEBUG
Detailed debug information.
Definition: Logger.php:32