ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\FingersCrossedHandler Class Reference

Buffers all records until a certain level is reached. More...

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

Public Member Functions

 __construct ($handler, $activationStrategy=null, $bufferSize=0, $bubble=true, $stopBuffering=true, $passthruLevel=null)
 
 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
bool
}} More...
 
 activate ()
 Manually activate this logger regardless of the activation strategy. More...
 
 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
bool 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...
 
 close ()
 {Closes the handler.This will be called automatically when the object is destroyed} More...
 
 reset ()
 
 clear ()
 Clears the buffer without flushing any messages down to the wrapped handler. 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
bool
} 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 ()
 
 reset ()
 
 isHandling (array $record)
 Checks whether the given record will be handled by this handler. More...
 
 handle (array $record)
 Handles a record. More...
 
 handleBatch (array $records)
 Handles a set of records at once. More...
 
 pushProcessor ($callback)
 Adds a processor in the stack. More...
 
 popProcessor ()
 Removes the processor on top of the stack and returns it. More...
 
 setFormatter (FormatterInterface $formatter)
 Sets the formatter. More...
 
 getFormatter ()
 Gets the formatter. More...
 
 reset ()
 

Protected Attributes

 $handler
 
 $activationStrategy
 
 $buffering = true
 
 $bufferSize
 
 $buffer = array()
 
 $stopBuffering
 
 $passthruLevel
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Private Member Functions

 flushBuffer ()
 Resets the state of the handler. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Detailed Description

Buffers all records until a certain level is reached.

The advantage of this approach is that you don't get any clutter in your log files. Only requests which actually trigger an error (or whatever your actionLevel is) will be in the logs, but they will contain all records, not only those above the level threshold.

You can find the various activation strategies in the Monolog\Handler\FingersCrossed\ namespace.

Author
Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be

Definition at line 31 of file FingersCrossedHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\FingersCrossedHandler::__construct (   $handler,
  $activationStrategy = null,
  $bufferSize = 0,
  $bubble = true,
  $stopBuffering = true,
  $passthruLevel = null 
)
Parameters
callable | HandlerInterface$handlerHandler or factory callable($record, $fingersCrossedHandler).
int | ActivationStrategyInterface$activationStrategyStrategy which determines when this handler takes action
int$bufferSizeHow many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
bool$bubbleWhether the messages that are handled can bubble up the stack or not
bool$stopBufferingWhether the handler should stop buffering after being triggered (default true)
int$passthruLevelMinimum level to always flush to handler on close, even if strategy not triggered

Definition at line 49 of file FingersCrossedHandler.php.

50 {
51 if (null === $activationStrategy) {
52 $activationStrategy = new ErrorLevelActivationStrategy(Logger::WARNING);
53 }
54
55 // convert simple int activationStrategy to an object
56 if (!$activationStrategy instanceof ActivationStrategyInterface) {
57 $activationStrategy = new ErrorLevelActivationStrategy($activationStrategy);
58 }
59
60 $this->handler = $handler;
61 $this->activationStrategy = $activationStrategy;
62 $this->bufferSize = $bufferSize;
63 $this->bubble = $bubble;
64 $this->stopBuffering = $stopBuffering;
65
66 if ($passthruLevel !== null) {
67 $this->passthruLevel = Logger::toMonologLevel($passthruLevel);
68 }
69
70 if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
71 throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
72 }
73 }
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:528
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53

References Monolog\Handler\FingersCrossedHandler\$activationStrategy, Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\FingersCrossedHandler\$bufferSize, Monolog\Handler\FingersCrossedHandler\$handler, Monolog\Handler\FingersCrossedHandler\$passthruLevel, Monolog\Handler\FingersCrossedHandler\$stopBuffering, Monolog\Logger\toMonologLevel(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

Member Function Documentation

◆ activate()

Monolog\Handler\FingersCrossedHandler::activate ( )

Manually activate this logger regardless of the activation strategy.

Definition at line 86 of file FingersCrossedHandler.php.

87 {
88 if ($this->stopBuffering) {
89 $this->buffering = false;
90 }
91 if (!$this->handler instanceof HandlerInterface) {
92 $record = end($this->buffer) ?: null;
93
94 $this->handler = call_user_func($this->handler, $record, $this);
95 if (!$this->handler instanceof HandlerInterface) {
96 throw new \RuntimeException("The factory callable should return a HandlerInterface");
97 }
98 }
99 $this->handler->handleBatch($this->buffer);
100 $this->buffer = array();
101 }

Referenced by Monolog\Handler\FingersCrossedHandler\handle().

+ Here is the caller graph for this function:

◆ clear()

Monolog\Handler\FingersCrossedHandler::clear ( )

Clears the buffer without flushing any messages down to the wrapped handler.

It also resets the handler to its initial buffering state.

Definition at line 153 of file FingersCrossedHandler.php.

154 {
155 $this->buffer = array();
156 $this->reset();
157 }

References Monolog\Handler\FingersCrossedHandler\reset().

+ Here is the call graph for this function:

◆ close()

Monolog\Handler\FingersCrossedHandler::close ( )

{Closes the handler.This will be called automatically when the object is destroyed}

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 132 of file FingersCrossedHandler.php.

133 {
134 $this->flushBuffer();
135 }
flushBuffer()
Resets the state of the handler.

References Monolog\Handler\FingersCrossedHandler\flushBuffer().

+ Here is the call graph for this function:

◆ flushBuffer()

Monolog\Handler\FingersCrossedHandler::flushBuffer ( )
private

Resets the state of the handler.

Stops forwarding records to the wrapped handler.

Definition at line 162 of file FingersCrossedHandler.php.

163 {
164 if (null !== $this->passthruLevel) {
166 $this->buffer = array_filter($this->buffer, function ($record) use ($level) {
167 return $record['level'] >= $level;
168 });
169 if (count($this->buffer) > 0) {
170 $this->handler->handleBatch($this->buffer);
171 }
172 }
173
174 $this->buffer = array();
175 $this->buffering = true;
176 }

References Monolog\Handler\AbstractHandler\$level, and Monolog\Handler\FingersCrossedHandler\$passthruLevel.

Referenced by Monolog\Handler\FingersCrossedHandler\close(), and Monolog\Handler\FingersCrossedHandler\reset().

+ Here is the caller graph for this function:

◆ handle()

Monolog\Handler\FingersCrossedHandler::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
bool 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.
}

Implements Monolog\Handler\HandlerInterface.

Definition at line 106 of file FingersCrossedHandler.php.

107 {
108 if ($this->processors) {
109 foreach ($this->processors as $processor) {
110 $record = call_user_func($processor, $record);
111 }
112 }
113
114 if ($this->buffering) {
115 $this->buffer[] = $record;
116 if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
117 array_shift($this->buffer);
118 }
119 if ($this->activationStrategy->isHandlerActivated($record)) {
120 $this->activate();
121 }
122 } else {
123 $this->handler->handle($record);
124 }
125
126 return false === $this->bubble;
127 }
activate()
Manually activate this logger regardless of the activation strategy.

References Monolog\Handler\AbstractHandler\$bubble, and Monolog\Handler\FingersCrossedHandler\activate().

+ Here is the call graph for this function:

◆ isHandling()

Monolog\Handler\FingersCrossedHandler::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
bool
}}

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 78 of file FingersCrossedHandler.php.

79 {
80 return true;
81 }

◆ reset()

Monolog\Handler\FingersCrossedHandler::reset ( )

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 137 of file FingersCrossedHandler.php.

138 {
139 $this->flushBuffer();
140
141 parent::reset();
142
143 if ($this->handler instanceof ResettableInterface) {
144 $this->handler->reset();
145 }
146 }

References Monolog\Handler\FingersCrossedHandler\flushBuffer().

Referenced by Monolog\Handler\FingersCrossedHandler\clear().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $activationStrategy

Monolog\Handler\FingersCrossedHandler::$activationStrategy
protected

◆ $buffer

Monolog\Handler\FingersCrossedHandler::$buffer = array()
protected

Definition at line 37 of file FingersCrossedHandler.php.

◆ $buffering

Monolog\Handler\FingersCrossedHandler::$buffering = true
protected

Definition at line 35 of file FingersCrossedHandler.php.

◆ $bufferSize

Monolog\Handler\FingersCrossedHandler::$bufferSize
protected

◆ $handler

Monolog\Handler\FingersCrossedHandler::$handler
protected

◆ $passthruLevel

Monolog\Handler\FingersCrossedHandler::$passthruLevel
protected

◆ $stopBuffering

Monolog\Handler\FingersCrossedHandler::$stopBuffering
protected

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