ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Handler\RedisHandler Class Reference

Logs to a Redis key using rpush. More...

+ Inheritance diagram for Monolog\Handler\RedisHandler:
+ Collaboration diagram for Monolog\Handler\RedisHandler:

Public Member Functions

 __construct ($redis, $key, $level=Logger::DEBUG, $bubble=true, $capSize=false)
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
Boolean
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 

Protected Member Functions

 write (array $record)
 
 writeCapped (array $record)
 Write and cap the collection Writes the record to the redis list and caps its. More...
 
 getDefaultFormatter ()
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Protected Attributes

 $capSize
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Private Attributes

 $redisClient
 
 $redisKey
 

Detailed Description

Logs to a Redis key using rpush.

usage example:

$log = new Logger('application'); $redis = new RedisHandler(new Predis("tcp://localhost:6379"), "logs", "prod"); $log->pushHandler($redis);

Author
Thomas Tourlourat thoma.nosp@m.s@to.nosp@m.urlou.nosp@m.rat..nosp@m.com

Definition at line 28 of file RedisHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\RedisHandler::__construct (   $redis,
  $key,
  $level = Logger::DEBUG,
  $bubble = true,
  $capSize = false 
)
Parameters
\Predis\Client | \Redis$redisThe redis instance
string$keyThe key name to push records to
int$levelThe minimum logging level at which this handler will be triggered
bool$bubbleWhether the messages that are handled can bubble up the stack or not
int$capSizeNumber of entries to limit list size to

Definition at line 41 of file RedisHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\RedisHandler\$capSize, $key, and Monolog\Handler\AbstractHandler\$level.

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  }
$key
Definition: croninfo.php:18

Member Function Documentation

◆ getDefaultFormatter()

Monolog\Handler\RedisHandler::getDefaultFormatter ( )
protected

Definition at line 93 of file RedisHandler.php.

94  {
95  return new LineFormatter();
96  }

◆ write()

Monolog\Handler\RedisHandler::write ( array  $record)
protected

Definition at line 57 of file RedisHandler.php.

References Monolog\Handler\RedisHandler\writeCapped().

58  {
59  if ($this->capSize) {
60  $this->writeCapped($record);
61  } else {
62  $this->redisClient->rpush($this->redisKey, $record["formatted"]);
63  }
64  }
writeCapped(array $record)
Write and cap the collection Writes the record to the redis list and caps its.
+ Here is the call graph for this function:

◆ writeCapped()

Monolog\Handler\RedisHandler::writeCapped ( array  $record)
protected

Write and cap the collection Writes the record to the redis list and caps its.

Parameters
array$recordassociative record array
Returns
void

Definition at line 73 of file RedisHandler.php.

References Monolog\Handler\RedisHandler\$capSize, and Monolog\Handler\RedisHandler\$redisKey.

Referenced by Monolog\Handler\RedisHandler\write().

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  }
+ Here is the caller graph for this function:

Field Documentation

◆ $capSize

Monolog\Handler\RedisHandler::$capSize
protected

◆ $redisClient

Monolog\Handler\RedisHandler::$redisClient
private

Definition at line 30 of file RedisHandler.php.

◆ $redisKey

Monolog\Handler\RedisHandler::$redisKey
private

Definition at line 31 of file RedisHandler.php.

Referenced by Monolog\Handler\RedisHandler\writeCapped().


The documentation for this class was generated from the following file: