ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
FingersCrossedHandler.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 
16 use Monolog\Logger;
17 
31 {
32  protected $handler;
34  protected $buffering = true;
35  protected $bufferSize;
36  protected $buffer = array();
37  protected $stopBuffering;
38  protected $passthruLevel;
39 
48  public function __construct($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true, $passthruLevel = null)
49  {
50  if (null === $activationStrategy) {
52  }
53 
54  // convert simple int activationStrategy to an object
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  }
73 
77  public function isHandling(array $record)
78  {
79  return true;
80  }
81 
85  public function handle(array $record)
86  {
87  if ($this->processors) {
88  foreach ($this->processors as $processor) {
89  $record = call_user_func($processor, $record);
90  }
91  }
92 
93  if ($this->buffering) {
94  $this->buffer[] = $record;
95  if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
96  array_shift($this->buffer);
97  }
98  if ($this->activationStrategy->isHandlerActivated($record)) {
99  if ($this->stopBuffering) {
100  $this->buffering = false;
101  }
102  if (!$this->handler instanceof HandlerInterface) {
103  $this->handler = call_user_func($this->handler, $record, $this);
104  if (!$this->handler instanceof HandlerInterface) {
105  throw new \RuntimeException("The factory callable should return a HandlerInterface");
106  }
107  }
108  $this->handler->handleBatch($this->buffer);
109  $this->buffer = array();
110  }
111  } else {
112  $this->handler->handle($record);
113  }
114 
115  return false === $this->bubble;
116  }
117 
121  public function close()
122  {
123  if (null !== $this->passthruLevel) {
125  $this->buffer = array_filter($this->buffer, function ($record) use ($level) {
126  return $record['level'] >= $level;
127  });
128  if (count($this->buffer) > 0) {
129  $this->handler->handleBatch($this->buffer);
130  $this->buffer = array();
131  }
132  }
133  }
134 
138  public function reset()
139  {
140  $this->buffering = true;
141  }
142 
148  public function clear()
149  {
150  $this->buffer = array();
151  $this->reset();
152  }
153 }
Base Handler class providing the Handler structure.
Buffers all records until a certain level is reached.
isHandling(array $record)
{Checks whether the given record will be handled by this handler.This is mostly done for performance ...
clear()
Clears the buffer without flushing any messages down to the wrapped handler.
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:403
reset()
Resets the state of the handler.
Interface for activation strategies for the FingersCrossedHandler.
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
handle(array $record)
{Handles a record.All records may be passed to this method, and the handler should discard those that...
__construct($handler, $activationStrategy=null, $bufferSize=0, $bubble=true, $stopBuffering=true, $passthruLevel=null)
Interface that all Monolog Handlers must implement.