scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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;
15 use Monolog\Formatter\FormatterInterface;
16 use Monolog\Formatter\LineFormatter;
17  
18 /**
19 * Base Handler class providing the Handler structure
20 *
21 * @author Jordi Boggiano <j.boggiano@seld.be>
22 */
23 abstract class AbstractHandler implements HandlerInterface
24 {
25 protected $level = Logger::DEBUG;
26 protected $bubble = true;
27  
28 /**
29 * @var FormatterInterface
30 */
31 protected $formatter;
32 protected $processors = array();
33  
34 /**
35 * @param int $level The minimum logging level at which this handler will be triggered
36 * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
37 */
38 public function __construct($level = Logger::DEBUG, $bubble = true)
39 {
40 $this->setLevel($level);
41 $this->bubble = $bubble;
42 }
43  
44 /**
45 * {@inheritdoc}
46 */
47 public function isHandling(array $record)
48 {
49 return $record['level'] >= $this->level;
50 }
51  
52 /**
53 * {@inheritdoc}
54 */
55 public function handleBatch(array $records)
56 {
57 foreach ($records as $record) {
58 $this->handle($record);
59 }
60 }
61  
62 /**
63 * Closes the handler.
64 *
65 * This will be called automatically when the object is destroyed
66 */
67 public function close()
68 {
69 }
70  
71 /**
72 * {@inheritdoc}
73 */
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  
84 /**
85 * {@inheritdoc}
86 */
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  
96 /**
97 * {@inheritdoc}
98 */
99 public function setFormatter(FormatterInterface $formatter)
100 {
101 $this->formatter = $formatter;
102  
103 return $this;
104 }
105  
106 /**
107 * {@inheritdoc}
108 */
109 public function getFormatter()
110 {
111 if (!$this->formatter) {
112 $this->formatter = $this->getDefaultFormatter();
113 }
114  
115 return $this->formatter;
116 }
117  
118 /**
119 * Sets minimum logging level at which this handler will be triggered.
120 *
121 * @param int|string $level Level or level name
122 * @return self
123 */
124 public function setLevel($level)
125 {
126 $this->level = Logger::toMonologLevel($level);
127  
128 return $this;
129 }
130  
131 /**
132 * Gets minimum logging level at which this handler will be triggered.
133 *
134 * @return int
135 */
136 public function getLevel()
137 {
138 return $this->level;
139 }
140  
141 /**
142 * Sets the bubbling behavior.
143 *
144 * @param Boolean $bubble true means that this handler allows bubbling.
145 * false means that bubbling is not permitted.
146 * @return self
147 */
148 public function setBubble($bubble)
149 {
150 $this->bubble = $bubble;
151  
152 return $this;
153 }
154  
155 /**
156 * Gets the bubbling behavior.
157 *
158 * @return Boolean true means that this handler allows bubbling.
159 * false means that bubbling is not permitted.
160 */
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  
177 /**
178 * Gets the default formatter.
179 *
180 * @return FormatterInterface
181 */
182 protected function getDefaultFormatter()
183 {
184 return new LineFormatter();
185 }
186 }