ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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 
12 namespace Monolog\Handler;
13 
14 use Monolog\Logger;
17 
23 abstract 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  } catch (\Throwable $e) {
173  // do nothing
174  }
175  }
176 
182  protected function getDefaultFormatter()
183  {
184  return new LineFormatter();
185  }
186 }
Base Handler class providing the Handler structure.
const DEBUG
Detailed debug information.
Definition: Logger.php:32
handle(array $record)
Handles a record.
setFormatter(FormatterInterface $formatter)
{Sets the formatter.self}
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:473
$records
Definition: simple_test.php:22
getDefaultFormatter()
Gets the default formatter.
getLevel()
Gets minimum logging level at which this handler will be triggered.
handleBatch(array $records)
{Handles a set of records at once.The records to handle (an array of record arrays)} ...
__construct($level=Logger::DEBUG, $bubble=true)
setBubble($bubble)
Sets the bubbling behavior.
getFormatter()
{Gets the formatter.FormatterInterface}
Create styles array
The data for the language used.
isHandling(array $record)
{Checks whether the given record will be handled by this handler.This is mostly done for performance ...
popProcessor()
{Removes the processor on top of the stack and returns it.callable}
setLevel($level)
Sets minimum logging level at which this handler will be triggered.
Formats incoming records into a one-line string.
Interface that all Monolog Handlers must implement.
pushProcessor($callback)
{Adds a processor in the stack.self}
getBubble()
Gets the bubbling behavior.