ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
BufferHandler.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 
14 use Monolog\Logger;
16 
26 {
27  protected $handler;
28  protected $bufferSize = 0;
29  protected $bufferLimit;
30  protected $flushOnOverflow;
31  protected $buffer = array();
32  protected $initialized = false;
33 
42  {
43  parent::__construct($level, $bubble);
44  $this->handler = $handler;
45  $this->bufferLimit = (int) $bufferLimit;
46  $this->flushOnOverflow = $flushOnOverflow;
47  }
48 
52  public function handle(array $record)
53  {
54  if ($record['level'] < $this->level) {
55  return false;
56  }
57 
58  if (!$this->initialized) {
59  // __destructor() doesn't get called on Fatal errors
60  register_shutdown_function(array($this, 'close'));
61  $this->initialized = true;
62  }
63 
64  if ($this->bufferLimit > 0 && $this->bufferSize === $this->bufferLimit) {
65  if ($this->flushOnOverflow) {
66  $this->flush();
67  } else {
68  array_shift($this->buffer);
69  $this->bufferSize--;
70  }
71  }
72 
73  if ($this->processors) {
74  foreach ($this->processors as $processor) {
75  $record = call_user_func($processor, $record);
76  }
77  }
78 
79  $this->buffer[] = $record;
80  $this->bufferSize++;
81 
82  return false === $this->bubble;
83  }
84 
85  public function flush()
86  {
87  if ($this->bufferSize === 0) {
88  return;
89  }
90 
91  $this->handler->handleBatch($this->buffer);
92  $this->clear();
93  }
94 
95  public function __destruct()
96  {
97  // suppress the parent behavior since we already have register_shutdown_function()
98  // to call close(), and the reference contained there will prevent this from being
99  // GC'd until the end of the request
100  }
101 
105  public function close()
106  {
107  $this->flush();
108  }
109 
113  public function clear()
114  {
115  $this->bufferSize = 0;
116  $this->buffer = array();
117  }
118 
119  public function reset()
120  {
121  $this->flush();
122 
123  parent::reset();
124 
125  if ($this->handler instanceof ResettableInterface) {
126  $this->handler->reset();
127  }
128  }
129 }
Base Handler class providing the Handler structure.
const DEBUG
Detailed debug information.
Definition: Logger.php:33
__construct(HandlerInterface $handler, $bufferLimit=0, $level=Logger::DEBUG, $bubble=true, $flushOnOverflow=false)
Handler or Processor implementing this interface will be reset when Logger::reset() is called...
Buffers all records until closing the handler and then pass them as batch.
handle(array $record)
{Handles a record.All records may be passed to this method, and the handler should discard those that...
Interface that all Monolog Handlers must implement.
clear()
Clears the buffer without flushing any messages down to the wrapped handler.