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