ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
Boolean
} 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
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...
 
 close ()
 {} More...
 
 reset ()
 Resets the state of the handler. More...
 
 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
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 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()
 

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\ namespace.

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

Definition at line 30 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.
Boolean$bubbleWhether the messages that are handled can bubble up the stack or not
Boolean$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 48 of file FingersCrossedHandler.php.

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.

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

References array.

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

86  {
87  if ($this->stopBuffering) {
88  $this->buffering = false;
89  }
90  if (!$this->handler instanceof HandlerInterface) {
91  $record = end($this->buffer) ?: null;
92 
93  $this->handler = call_user_func($this->handler, $record, $this);
94  if (!$this->handler instanceof HandlerInterface) {
95  throw new \RuntimeException("The factory callable should return a HandlerInterface");
96  }
97  }
98  $this->handler->handleBatch($this->buffer);
99  $this->buffer = array();
100  }
Create styles array
The data for the language used.
+ 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 158 of file FingersCrossedHandler.php.

References array, and Monolog\Handler\FingersCrossedHandler\reset().

159  {
160  $this->buffer = array();
161  $this->reset();
162  }
reset()
Resets the state of the handler.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ close()

Monolog\Handler\FingersCrossedHandler::close ( )

{}

Definition at line 131 of file FingersCrossedHandler.php.

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

132  {
133  if (null !== $this->passthruLevel) {
135  $this->buffer = array_filter($this->buffer, function ($record) use ($level) {
136  return $record['level'] >= $level;
137  });
138  if (count($this->buffer) > 0) {
139  $this->handler->handleBatch($this->buffer);
140  $this->buffer = array();
141  }
142  }
143  }
Create styles array
The data for the language used.

◆ 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
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.
}

Implements Monolog\Handler\HandlerInterface.

Definition at line 105 of file FingersCrossedHandler.php.

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

Referenced by Monolog\Handler\FingersCrossedHandlerTest\testHandleWithBadCallbackThrowsException(), and Monolog\Handler\FingersCrossedHandlerTest\testHandleWithCallback().

106  {
107  if ($this->processors) {
108  foreach ($this->processors as $processor) {
109  $record = call_user_func($processor, $record);
110  }
111  }
112 
113  if ($this->buffering) {
114  $this->buffer[] = $record;
115  if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
116  array_shift($this->buffer);
117  }
118  if ($this->activationStrategy->isHandlerActivated($record)) {
119  $this->activate();
120  }
121  } else {
122  $this->handler->handle($record);
123  }
124 
125  return false === $this->bubble;
126  }
activate()
Manually activate this logger regardless of the activation strategy.
+ Here is the call graph for this function:
+ Here is the caller 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
Boolean
}

Implements Monolog\Handler\HandlerInterface.

Definition at line 77 of file FingersCrossedHandler.php.

78  {
79  return true;
80  }

◆ reset()

Monolog\Handler\FingersCrossedHandler::reset ( )

Resets the state of the handler.

Stops forwarding records to the wrapped handler.

Definition at line 148 of file FingersCrossedHandler.php.

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

149  {
150  $this->buffering = true;
151  }
+ 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 36 of file FingersCrossedHandler.php.

◆ $buffering

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

Definition at line 34 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: