ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
17
23abstract class AbstractHandler implements HandlerInterface
24{
25 protected $level = Logger::DEBUG;
26 protected $bubble = true;
27
31 protected $formatter;
32 protected $processors = array();
33
38 public function __construct($level = Logger::DEBUG, $bubble = true)
39 {
40 $this->setLevel($level);
41 $this->bubble = $bubble;
42 }
43
47 public function isHandling(array $record)
48 {
49 return $record['level'] >= $this->level;
50 }
51
55 public function handleBatch(array $records)
56 {
57 foreach ($records as $record) {
58 $this->handle($record);
59 }
60 }
61
67 public function close()
68 {
69 }
70
74 public function pushProcessor($callback)
75 {
76 if (!is_callable($callback)) {
77 throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
78 }
79 array_unshift($this->processors, $callback);
80
81 return $this;
82 }
83
87 public function popProcessor()
88 {
89 if (!$this->processors) {
90 throw new \LogicException('You tried to pop from an empty processor stack.');
91 }
92
93 return array_shift($this->processors);
94 }
95
100 {
101 $this->formatter = $formatter;
102
103 return $this;
104 }
105
109 public function getFormatter()
110 {
111 if (!$this->formatter) {
112 $this->formatter = $this->getDefaultFormatter();
113 }
114
115 return $this->formatter;
116 }
117
124 public function setLevel($level)
125 {
126 $this->level = Logger::toMonologLevel($level);
127
128 return $this;
129 }
130
136 public function getLevel()
137 {
138 return $this->level;
139 }
140
148 public function setBubble($bubble)
149 {
150 $this->bubble = $bubble;
151
152 return $this;
153 }
154
161 public function getBubble()
162 {
163 return $this->bubble;
164 }
165
166 public function __destruct()
167 {
168 try {
169 $this->close();
170 } catch (\Exception $e) {
171 // do nothing
172 }
173 }
174
180 protected function getDefaultFormatter()
181 {
182 return new LineFormatter();
183 }
184}
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:28
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:403
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Interface that all Monolog Handlers must implement.
handle(array $record)
Handles a record.
$records
Definition: simple_test.php:17