ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
18 
32 {
33  protected $handler;
35  protected $buffering = true;
36  protected $bufferSize;
37  protected $buffer = array();
38  protected $stopBuffering;
39  protected $passthruLevel;
40 
49  public function __construct($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true, $passthruLevel = null)
50  {
51  if (null === $activationStrategy) {
53  }
54 
55  // convert simple int activationStrategy to an object
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  }
74 
78  public function isHandling(array $record)
79  {
80  return true;
81  }
82 
86  public function activate()
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  }
102 
106  public function handle(array $record)
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  }
128 
132  public function close()
133  {
134  $this->flushBuffer();
135  }
136 
137  public function reset()
138  {
139  $this->flushBuffer();
140 
141  parent::reset();
142 
143  if ($this->handler instanceof ResettableInterface) {
144  $this->handler->reset();
145  }
146  }
147 
153  public function clear()
154  {
155  $this->buffer = array();
156  $this->reset();
157  }
158 
162  private function flushBuffer()
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  }
177 }
activate()
Manually activate this logger regardless of the activation strategy.
Base Handler class providing the Handler structure.
flushBuffer()
Resets the state of the handler.
Buffers all records until a certain level is reached.
Handler or Processor implementing this interface will be reset when Logger::reset() is called...
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:528
Interface for activation strategies for the FingersCrossedHandler.
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53
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.