ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 activate()
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  }
101 
105  public function handle(array $record)
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  }
127 
131  public function close()
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  }
144 
148  public function reset()
149  {
150  $this->buffering = true;
151  }
152 
158  public function clear()
159  {
160  $this->buffer = array();
161  $this->reset();
162  }
163 }
activate()
Manually activate this logger regardless of the activation strategy.
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:473
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
Create styles array
The data for the language used.
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.