ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractHandler.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
13
18
25{
26 protected $level = Logger::DEBUG;
27 protected $bubble = true;
28
32 protected $formatter;
33 protected $processors = array();
34
39 public function __construct($level = Logger::DEBUG, $bubble = true)
40 {
41 $this->setLevel($level);
42 $this->bubble = $bubble;
43 }
44
48 public function isHandling(array $record)
49 {
50 return $record['level'] >= $this->level;
51 }
52
56 public function handleBatch(array $records)
57 {
58 foreach ($records as $record) {
59 $this->handle($record);
60 }
61 }
62
68 public function close()
69 {
70 }
71
75 public function pushProcessor($callback)
76 {
77 if (!is_callable($callback)) {
78 throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
79 }
80 array_unshift($this->processors, $callback);
81
82 return $this;
83 }
84
88 public function popProcessor()
89 {
90 if (!$this->processors) {
91 throw new \LogicException('You tried to pop from an empty processor stack.');
92 }
93
94 return array_shift($this->processors);
95 }
96
101 {
102 $this->formatter = $formatter;
103
104 return $this;
105 }
106
110 public function getFormatter()
111 {
112 if (!$this->formatter) {
113 $this->formatter = $this->getDefaultFormatter();
114 }
115
116 return $this->formatter;
117 }
118
125 public function setLevel($level)
126 {
127 $this->level = Logger::toMonologLevel($level);
128
129 return $this;
130 }
131
137 public function getLevel()
138 {
139 return $this->level;
140 }
141
149 public function setBubble($bubble)
150 {
151 $this->bubble = $bubble;
152
153 return $this;
154 }
155
162 public function getBubble()
163 {
164 return $this->bubble;
165 }
166
167 public function __destruct()
168 {
169 try {
170 $this->close();
171 } catch (\Exception $e) {
172 // do nothing
173 } catch (\Throwable $e) {
174 // do nothing
175 }
176 }
177
178 public function reset()
179 {
180 foreach ($this->processors as $processor) {
181 if ($processor instanceof ResettableInterface) {
182 $processor->reset();
183 }
184 }
185 }
186
192 protected function getDefaultFormatter()
193 {
194 return new LineFormatter();
195 }
196}
An exception for terminatinating execution or to throw for unit testing.
Formats incoming records into a one-line string.
Base Handler class providing the Handler structure.
setBubble($bubble)
Sets the bubbling behavior.
getBubble()
Gets the bubbling behavior.
getFormatter()
{Gets the formatter.FormatterInterface}
handleBatch(array $records)
{Handles a set of records at once.}
setFormatter(FormatterInterface $formatter)
{Sets the formatter.self}
setLevel($level)
Sets minimum logging level at which this handler will be triggered.
__construct($level=Logger::DEBUG, $bubble=true)
pushProcessor($callback)
{Adds a processor in the stack.self}
popProcessor()
{Removes the processor on top of the stack and returns it.callable}
isHandling(array $record)
{Checks whether the given record will be handled by this handler.This is mostly done for performance ...
getDefaultFormatter()
Gets the default formatter.
getLevel()
Gets minimum logging level at which this handler will be triggered.
Monolog log channel.
Definition: Logger.php:29
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:528
const DEBUG
Detailed debug information.
Definition: Logger.php:33
Interface that all Monolog Handlers must implement.
handle(array $record)
Handles a record.
Handler or Processor implementing this interface will be reset when Logger::reset() is called.
$records
Definition: simple_test.php:22