@@ -33,224 +33,224 @@ |
||
33 | 33 | */ |
34 | 34 | class LoggerLevel { |
35 | 35 | |
36 | - const OFF = 2147483647; |
|
37 | - const FATAL = 50000; |
|
38 | - const ERROR = 40000; |
|
39 | - const WARN = 30000; |
|
40 | - const INFO = 20000; |
|
41 | - const DEBUG = 10000; |
|
42 | - const ALL = -2147483647; |
|
36 | + const OFF = 2147483647; |
|
37 | + const FATAL = 50000; |
|
38 | + const ERROR = 40000; |
|
39 | + const WARN = 30000; |
|
40 | + const INFO = 20000; |
|
41 | + const DEBUG = 10000; |
|
42 | + const ALL = -2147483647; |
|
43 | 43 | |
44 | - /** |
|
45 | - * TODO: check if still necessary or to be refactored |
|
46 | - * @var integer |
|
47 | - */ |
|
48 | - private $level; |
|
44 | + /** |
|
45 | + * TODO: check if still necessary or to be refactored |
|
46 | + * @var integer |
|
47 | + */ |
|
48 | + private $level; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Contains a list of instantiated levels |
|
52 | - */ |
|
53 | - private static $levelMap; |
|
50 | + /** |
|
51 | + * Contains a list of instantiated levels |
|
52 | + */ |
|
53 | + private static $levelMap; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - private $levelStr; |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + private $levelStr; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var integer |
|
62 | - */ |
|
63 | - private $syslogEquivalent; |
|
60 | + /** |
|
61 | + * @var integer |
|
62 | + */ |
|
63 | + private $syslogEquivalent; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Constructor |
|
67 | - * |
|
68 | - * @param integer $level |
|
69 | - * @param string $levelStr |
|
70 | - * @param integer $syslogEquivalent |
|
71 | - */ |
|
72 | - private function __construct($level, $levelStr, $syslogEquivalent) { |
|
73 | - $this->level = $level; |
|
74 | - $this->levelStr = $levelStr; |
|
75 | - $this->syslogEquivalent = $syslogEquivalent; |
|
76 | - } |
|
65 | + /** |
|
66 | + * Constructor |
|
67 | + * |
|
68 | + * @param integer $level |
|
69 | + * @param string $levelStr |
|
70 | + * @param integer $syslogEquivalent |
|
71 | + */ |
|
72 | + private function __construct($level, $levelStr, $syslogEquivalent) { |
|
73 | + $this->level = $level; |
|
74 | + $this->levelStr = $levelStr; |
|
75 | + $this->syslogEquivalent = $syslogEquivalent; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Two priorities are equal if their level fields are equal. |
|
80 | - * |
|
81 | - * @param object $o |
|
82 | - * @return boolean |
|
83 | - */ |
|
84 | - public function equals($o) { |
|
85 | - if($o instanceof LoggerLevel) { |
|
86 | - if($this->level == $o->level) { |
|
87 | - return true; |
|
88 | - } |
|
89 | - } else { |
|
90 | - return false; |
|
91 | - } |
|
92 | - } |
|
78 | + /** |
|
79 | + * Two priorities are equal if their level fields are equal. |
|
80 | + * |
|
81 | + * @param object $o |
|
82 | + * @return boolean |
|
83 | + */ |
|
84 | + public function equals($o) { |
|
85 | + if($o instanceof LoggerLevel) { |
|
86 | + if($this->level == $o->level) { |
|
87 | + return true; |
|
88 | + } |
|
89 | + } else { |
|
90 | + return false; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Returns an Off Level |
|
96 | - * @static |
|
97 | - * @return LoggerLevel |
|
98 | - */ |
|
99 | - public static function getLevelOff() { |
|
100 | - if(!isset(self::$levelMap[LoggerLevel::OFF])) { |
|
101 | - self::$levelMap[LoggerLevel::OFF] = new LoggerLevel(LoggerLevel::OFF, 'OFF', 0); |
|
102 | - } |
|
103 | - return self::$levelMap[LoggerLevel::OFF]; |
|
104 | - } |
|
94 | + /** |
|
95 | + * Returns an Off Level |
|
96 | + * @static |
|
97 | + * @return LoggerLevel |
|
98 | + */ |
|
99 | + public static function getLevelOff() { |
|
100 | + if(!isset(self::$levelMap[LoggerLevel::OFF])) { |
|
101 | + self::$levelMap[LoggerLevel::OFF] = new LoggerLevel(LoggerLevel::OFF, 'OFF', 0); |
|
102 | + } |
|
103 | + return self::$levelMap[LoggerLevel::OFF]; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Returns a Fatal Level |
|
108 | - * @static |
|
109 | - * @return LoggerLevel |
|
110 | - */ |
|
111 | - public static function getLevelFatal() { |
|
112 | - if(!isset(self::$levelMap[LoggerLevel::FATAL])) { |
|
113 | - self::$levelMap[LoggerLevel::FATAL] = new LoggerLevel(LoggerLevel::FATAL, 'FATAL', 0); |
|
114 | - } |
|
115 | - return self::$levelMap[LoggerLevel::FATAL]; |
|
116 | - } |
|
106 | + /** |
|
107 | + * Returns a Fatal Level |
|
108 | + * @static |
|
109 | + * @return LoggerLevel |
|
110 | + */ |
|
111 | + public static function getLevelFatal() { |
|
112 | + if(!isset(self::$levelMap[LoggerLevel::FATAL])) { |
|
113 | + self::$levelMap[LoggerLevel::FATAL] = new LoggerLevel(LoggerLevel::FATAL, 'FATAL', 0); |
|
114 | + } |
|
115 | + return self::$levelMap[LoggerLevel::FATAL]; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Returns an Error Level |
|
120 | - * @static |
|
121 | - * @return LoggerLevel |
|
122 | - */ |
|
123 | - public static function getLevelError() { |
|
124 | - if(!isset(self::$levelMap[LoggerLevel::ERROR])) { |
|
125 | - self::$levelMap[LoggerLevel::ERROR] = new LoggerLevel(LoggerLevel::ERROR, 'ERROR', 3); |
|
126 | - } |
|
127 | - return self::$levelMap[LoggerLevel::ERROR]; |
|
128 | - } |
|
118 | + /** |
|
119 | + * Returns an Error Level |
|
120 | + * @static |
|
121 | + * @return LoggerLevel |
|
122 | + */ |
|
123 | + public static function getLevelError() { |
|
124 | + if(!isset(self::$levelMap[LoggerLevel::ERROR])) { |
|
125 | + self::$levelMap[LoggerLevel::ERROR] = new LoggerLevel(LoggerLevel::ERROR, 'ERROR', 3); |
|
126 | + } |
|
127 | + return self::$levelMap[LoggerLevel::ERROR]; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Returns a Warn Level |
|
132 | - * @static |
|
133 | - * @return LoggerLevel |
|
134 | - */ |
|
135 | - public static function getLevelWarn() { |
|
136 | - if(!isset(self::$levelMap[LoggerLevel::WARN])) { |
|
137 | - self::$levelMap[LoggerLevel::WARN] = new LoggerLevel(LoggerLevel::WARN, 'WARN', 4); |
|
138 | - } |
|
139 | - return self::$levelMap[LoggerLevel::WARN]; |
|
140 | - } |
|
130 | + /** |
|
131 | + * Returns a Warn Level |
|
132 | + * @static |
|
133 | + * @return LoggerLevel |
|
134 | + */ |
|
135 | + public static function getLevelWarn() { |
|
136 | + if(!isset(self::$levelMap[LoggerLevel::WARN])) { |
|
137 | + self::$levelMap[LoggerLevel::WARN] = new LoggerLevel(LoggerLevel::WARN, 'WARN', 4); |
|
138 | + } |
|
139 | + return self::$levelMap[LoggerLevel::WARN]; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Returns an Info Level |
|
144 | - * @static |
|
145 | - * @return LoggerLevel |
|
146 | - */ |
|
147 | - public static function getLevelInfo() { |
|
148 | - if(!isset(self::$levelMap[LoggerLevel::INFO])) { |
|
149 | - self::$levelMap[LoggerLevel::INFO] = new LoggerLevel(LoggerLevel::INFO, 'INFO', 6); |
|
150 | - } |
|
151 | - return self::$levelMap[LoggerLevel::INFO]; |
|
152 | - } |
|
142 | + /** |
|
143 | + * Returns an Info Level |
|
144 | + * @static |
|
145 | + * @return LoggerLevel |
|
146 | + */ |
|
147 | + public static function getLevelInfo() { |
|
148 | + if(!isset(self::$levelMap[LoggerLevel::INFO])) { |
|
149 | + self::$levelMap[LoggerLevel::INFO] = new LoggerLevel(LoggerLevel::INFO, 'INFO', 6); |
|
150 | + } |
|
151 | + return self::$levelMap[LoggerLevel::INFO]; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * Returns a Debug Level |
|
156 | - * @static |
|
157 | - * @return LoggerLevel |
|
158 | - */ |
|
159 | - public static function getLevelDebug() { |
|
160 | - if(!isset(self::$levelMap[LoggerLevel::DEBUG])) { |
|
161 | - self::$levelMap[LoggerLevel::DEBUG] = new LoggerLevel(LoggerLevel::DEBUG, 'DEBUG', 7); |
|
162 | - } |
|
163 | - return self::$levelMap[LoggerLevel::DEBUG]; |
|
164 | - } |
|
154 | + /** |
|
155 | + * Returns a Debug Level |
|
156 | + * @static |
|
157 | + * @return LoggerLevel |
|
158 | + */ |
|
159 | + public static function getLevelDebug() { |
|
160 | + if(!isset(self::$levelMap[LoggerLevel::DEBUG])) { |
|
161 | + self::$levelMap[LoggerLevel::DEBUG] = new LoggerLevel(LoggerLevel::DEBUG, 'DEBUG', 7); |
|
162 | + } |
|
163 | + return self::$levelMap[LoggerLevel::DEBUG]; |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Returns an All Level |
|
168 | - * @static |
|
169 | - * @return LoggerLevel |
|
170 | - */ |
|
171 | - public static function getLevelAll() { |
|
172 | - if(!isset(self::$levelMap[LoggerLevel::ALL])) { |
|
173 | - self::$levelMap[LoggerLevel::ALL] = new LoggerLevel(LoggerLevel::ALL, 'ALL', 7); |
|
174 | - } |
|
175 | - return self::$levelMap[LoggerLevel::ALL]; |
|
176 | - } |
|
166 | + /** |
|
167 | + * Returns an All Level |
|
168 | + * @static |
|
169 | + * @return LoggerLevel |
|
170 | + */ |
|
171 | + public static function getLevelAll() { |
|
172 | + if(!isset(self::$levelMap[LoggerLevel::ALL])) { |
|
173 | + self::$levelMap[LoggerLevel::ALL] = new LoggerLevel(LoggerLevel::ALL, 'ALL', 7); |
|
174 | + } |
|
175 | + return self::$levelMap[LoggerLevel::ALL]; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * Return the syslog equivalent of this priority as an integer. |
|
180 | - * @final |
|
181 | - * @return integer |
|
182 | - */ |
|
183 | - public function getSyslogEquivalent() { |
|
184 | - return $this->syslogEquivalent; |
|
185 | - } |
|
178 | + /** |
|
179 | + * Return the syslog equivalent of this priority as an integer. |
|
180 | + * @final |
|
181 | + * @return integer |
|
182 | + */ |
|
183 | + public function getSyslogEquivalent() { |
|
184 | + return $this->syslogEquivalent; |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Returns <i>true</i> if this level has a higher or equal |
|
189 | - * level than the level passed as argument, <i>false</i> |
|
190 | - * otherwise. |
|
191 | - * |
|
192 | - * <p>You should think twice before overriding the default |
|
193 | - * implementation of <i>isGreaterOrEqual</i> method. |
|
194 | - * |
|
195 | - * @param LoggerLevel $r |
|
196 | - * @return boolean |
|
197 | - */ |
|
198 | - public function isGreaterOrEqual($r) { |
|
199 | - return $this->level >= $r->level; |
|
200 | - } |
|
187 | + /** |
|
188 | + * Returns <i>true</i> if this level has a higher or equal |
|
189 | + * level than the level passed as argument, <i>false</i> |
|
190 | + * otherwise. |
|
191 | + * |
|
192 | + * <p>You should think twice before overriding the default |
|
193 | + * implementation of <i>isGreaterOrEqual</i> method. |
|
194 | + * |
|
195 | + * @param LoggerLevel $r |
|
196 | + * @return boolean |
|
197 | + */ |
|
198 | + public function isGreaterOrEqual($r) { |
|
199 | + return $this->level >= $r->level; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Returns the string representation of this priority. |
|
204 | - * @return string |
|
205 | - * @final |
|
206 | - */ |
|
207 | - public function toString() { |
|
208 | - return $this->levelStr; |
|
209 | - } |
|
202 | + /** |
|
203 | + * Returns the string representation of this priority. |
|
204 | + * @return string |
|
205 | + * @final |
|
206 | + */ |
|
207 | + public function toString() { |
|
208 | + return $this->levelStr; |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Returns the integer representation of this level. |
|
213 | - * @return integer |
|
214 | - */ |
|
215 | - public function toInt() { |
|
216 | - return $this->level; |
|
217 | - } |
|
211 | + /** |
|
212 | + * Returns the integer representation of this level. |
|
213 | + * @return integer |
|
214 | + */ |
|
215 | + public function toInt() { |
|
216 | + return $this->level; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Convert the string passed as argument to a level. If the |
|
221 | - * conversion fails, then this method returns a DEBUG Level. |
|
222 | - * |
|
223 | - * @param mixed $arg |
|
224 | - * @param LoggerLevel $default |
|
225 | - * @static |
|
226 | - */ |
|
227 | - public static function toLevel($arg, $defaultLevel = null) { |
|
228 | - if($defaultLevel === null) { |
|
229 | - return self::toLevel($arg, self::getLevelDebug()); |
|
230 | - } else { |
|
231 | - if(is_int($arg)) { |
|
232 | - switch($arg) { |
|
233 | - case self::ALL: return self::getLevelAll(); |
|
234 | - case self::DEBUG: return self::getLevelDebug(); |
|
235 | - case self::INFO: return self::getLevelInfo(); |
|
236 | - case self::WARN: return self::getLevelWarn(); |
|
237 | - case self::ERROR: return self::getLevelError(); |
|
238 | - case self::FATAL: return self::getLevelFatal(); |
|
239 | - case self::OFF: return self::getLevelOff(); |
|
240 | - default: return $defaultLevel; |
|
241 | - } |
|
242 | - } else { |
|
243 | - switch(strtoupper($arg)) { |
|
244 | - case 'ALL': return self::getLevelAll(); |
|
245 | - case 'DEBUG': return self::getLevelDebug(); |
|
246 | - case 'INFO': return self::getLevelInfo(); |
|
247 | - case 'WARN': return self::getLevelWarn(); |
|
248 | - case 'ERROR': return self::getLevelError(); |
|
249 | - case 'FATAL': return self::getLevelFatal(); |
|
250 | - case 'OFF': return self::getLevelOff(); |
|
251 | - default: return $defaultLevel; |
|
252 | - } |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
219 | + /** |
|
220 | + * Convert the string passed as argument to a level. If the |
|
221 | + * conversion fails, then this method returns a DEBUG Level. |
|
222 | + * |
|
223 | + * @param mixed $arg |
|
224 | + * @param LoggerLevel $default |
|
225 | + * @static |
|
226 | + */ |
|
227 | + public static function toLevel($arg, $defaultLevel = null) { |
|
228 | + if($defaultLevel === null) { |
|
229 | + return self::toLevel($arg, self::getLevelDebug()); |
|
230 | + } else { |
|
231 | + if(is_int($arg)) { |
|
232 | + switch($arg) { |
|
233 | + case self::ALL: return self::getLevelAll(); |
|
234 | + case self::DEBUG: return self::getLevelDebug(); |
|
235 | + case self::INFO: return self::getLevelInfo(); |
|
236 | + case self::WARN: return self::getLevelWarn(); |
|
237 | + case self::ERROR: return self::getLevelError(); |
|
238 | + case self::FATAL: return self::getLevelFatal(); |
|
239 | + case self::OFF: return self::getLevelOff(); |
|
240 | + default: return $defaultLevel; |
|
241 | + } |
|
242 | + } else { |
|
243 | + switch(strtoupper($arg)) { |
|
244 | + case 'ALL': return self::getLevelAll(); |
|
245 | + case 'DEBUG': return self::getLevelDebug(); |
|
246 | + case 'INFO': return self::getLevelInfo(); |
|
247 | + case 'WARN': return self::getLevelWarn(); |
|
248 | + case 'ERROR': return self::getLevelError(); |
|
249 | + case 'FATAL': return self::getLevelFatal(); |
|
250 | + case 'OFF': return self::getLevelOff(); |
|
251 | + default: return $defaultLevel; |
|
252 | + } |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | 256 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Extend this abstract class to create your own log layout format. |
@@ -26,45 +26,45 @@ discard block |
||
26 | 26 | * @abstract |
27 | 27 | */ |
28 | 28 | abstract class LoggerLayout { |
29 | - /** |
|
30 | - * Activates options for this layout. |
|
31 | - * Override this method if you have options to be activated. |
|
32 | - */ |
|
33 | - public function activateOptions() { |
|
34 | - return true; |
|
35 | - } |
|
29 | + /** |
|
30 | + * Activates options for this layout. |
|
31 | + * Override this method if you have options to be activated. |
|
32 | + */ |
|
33 | + public function activateOptions() { |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Override this method to create your own layout format. |
|
39 | - * |
|
40 | - * @param LoggerLoggingEvent |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function format(LoggerLoggingEvent $event) { |
|
44 | - return $event->getRenderedMessage(); |
|
45 | - } |
|
37 | + /** |
|
38 | + * Override this method to create your own layout format. |
|
39 | + * |
|
40 | + * @param LoggerLoggingEvent |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function format(LoggerLoggingEvent $event) { |
|
44 | + return $event->getRenderedMessage(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Returns the content type output by this layout. |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getContentType() { |
|
52 | - return "text/plain"; |
|
53 | - } |
|
47 | + /** |
|
48 | + * Returns the content type output by this layout. |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getContentType() { |
|
52 | + return "text/plain"; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the footer for the layout format. |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function getFooter() { |
|
60 | - return null; |
|
61 | - } |
|
55 | + /** |
|
56 | + * Returns the footer for the layout format. |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function getFooter() { |
|
60 | + return null; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Returns the header for the layout format. |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getHeader() { |
|
68 | - return null; |
|
69 | - } |
|
63 | + /** |
|
64 | + * Returns the header for the layout format. |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getHeader() { |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Log objects using customized renderers that implement {@link LoggerRendererObject}. |
@@ -36,114 +36,114 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class LoggerRendererMap { |
38 | 38 | |
39 | - /** |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $map; |
|
39 | + /** |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $map; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var LoggerDefaultRenderer |
|
46 | - */ |
|
47 | - private $defaultRenderer; |
|
44 | + /** |
|
45 | + * @var LoggerDefaultRenderer |
|
46 | + */ |
|
47 | + private $defaultRenderer; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Constructor |
|
51 | - */ |
|
52 | - public function __construct() { |
|
53 | - $this->map = array(); |
|
54 | - $this->defaultRenderer = new LoggerRendererDefault(); |
|
55 | - } |
|
49 | + /** |
|
50 | + * Constructor |
|
51 | + */ |
|
52 | + public function __construct() { |
|
53 | + $this->map = array(); |
|
54 | + $this->defaultRenderer = new LoggerRendererDefault(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Add a renderer to a hierarchy passed as parameter. |
|
59 | - * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
60 | - * |
|
61 | - * @param LoggerHierarchy $repository a logger repository. |
|
62 | - * @param string $renderedClassName |
|
63 | - * @param string $renderingClassName |
|
64 | - * @static |
|
65 | - */ |
|
66 | - public function addRenderer($renderedClassName, $renderingClassName) { |
|
67 | - $renderer = LoggerReflectionUtils::createObject($renderingClassName); |
|
68 | - if($renderer == null) { |
|
69 | - return; |
|
70 | - } else { |
|
71 | - $this->put($renderedClassName, $renderer); |
|
72 | - } |
|
73 | - } |
|
57 | + /** |
|
58 | + * Add a renderer to a hierarchy passed as parameter. |
|
59 | + * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
60 | + * |
|
61 | + * @param LoggerHierarchy $repository a logger repository. |
|
62 | + * @param string $renderedClassName |
|
63 | + * @param string $renderingClassName |
|
64 | + * @static |
|
65 | + */ |
|
66 | + public function addRenderer($renderedClassName, $renderingClassName) { |
|
67 | + $renderer = LoggerReflectionUtils::createObject($renderingClassName); |
|
68 | + if($renderer == null) { |
|
69 | + return; |
|
70 | + } else { |
|
71 | + $this->put($renderedClassName, $renderer); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Find the appropriate renderer for the class type of the |
|
78 | - * <var>o</var> parameter. |
|
79 | - * |
|
80 | - * This is accomplished by calling the {@link getByObject()} |
|
81 | - * method if <var>o</var> is object or using {@link LoggerRendererDefault}. |
|
82 | - * Once a renderer is found, it is applied on the object <var>o</var> and |
|
83 | - * the result is returned as a string. |
|
84 | - * |
|
85 | - * @param mixed $o |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function findAndRender($o) { |
|
89 | - if($o == null) { |
|
90 | - return null; |
|
91 | - } else { |
|
92 | - if(is_object($o)) { |
|
93 | - $renderer = $this->getByObject($o); |
|
94 | - if($renderer !== null) { |
|
95 | - return $renderer->render($o); |
|
96 | - } else { |
|
97 | - return null; |
|
98 | - } |
|
99 | - } else { |
|
100 | - $renderer = $this->defaultRenderer; |
|
101 | - return $renderer->render($o); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
76 | + /** |
|
77 | + * Find the appropriate renderer for the class type of the |
|
78 | + * <var>o</var> parameter. |
|
79 | + * |
|
80 | + * This is accomplished by calling the {@link getByObject()} |
|
81 | + * method if <var>o</var> is object or using {@link LoggerRendererDefault}. |
|
82 | + * Once a renderer is found, it is applied on the object <var>o</var> and |
|
83 | + * the result is returned as a string. |
|
84 | + * |
|
85 | + * @param mixed $o |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function findAndRender($o) { |
|
89 | + if($o == null) { |
|
90 | + return null; |
|
91 | + } else { |
|
92 | + if(is_object($o)) { |
|
93 | + $renderer = $this->getByObject($o); |
|
94 | + if($renderer !== null) { |
|
95 | + return $renderer->render($o); |
|
96 | + } else { |
|
97 | + return null; |
|
98 | + } |
|
99 | + } else { |
|
100 | + $renderer = $this->defaultRenderer; |
|
101 | + return $renderer->render($o); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
108 | - * class of the object parameter. |
|
109 | - * |
|
110 | - * @param mixed $o |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function getByObject($o) { |
|
114 | - return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
115 | - } |
|
106 | + /** |
|
107 | + * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
108 | + * class of the object parameter. |
|
109 | + * |
|
110 | + * @param mixed $o |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function getByObject($o) { |
|
114 | + return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * Search the parents of <var>clazz</var> for a renderer. |
|
120 | - * |
|
121 | - * The renderer closest in the hierarchy will be returned. If no |
|
122 | - * renderers could be found, then the default renderer is returned. |
|
123 | - * |
|
124 | - * @param string $class |
|
125 | - * @return LoggerRendererObject |
|
126 | - */ |
|
127 | - public function getByClassName($class) { |
|
128 | - $r = null; |
|
129 | - for($c = strtolower($class); !empty($c); $c = get_parent_class($c)) { |
|
130 | - if(isset($this->map[$c])) { |
|
131 | - return $this->map[$c]; |
|
132 | - } |
|
133 | - } |
|
134 | - return $this->defaultRenderer; |
|
135 | - } |
|
118 | + /** |
|
119 | + * Search the parents of <var>clazz</var> for a renderer. |
|
120 | + * |
|
121 | + * The renderer closest in the hierarchy will be returned. If no |
|
122 | + * renderers could be found, then the default renderer is returned. |
|
123 | + * |
|
124 | + * @param string $class |
|
125 | + * @return LoggerRendererObject |
|
126 | + */ |
|
127 | + public function getByClassName($class) { |
|
128 | + $r = null; |
|
129 | + for($c = strtolower($class); !empty($c); $c = get_parent_class($c)) { |
|
130 | + if(isset($this->map[$c])) { |
|
131 | + return $this->map[$c]; |
|
132 | + } |
|
133 | + } |
|
134 | + return $this->defaultRenderer; |
|
135 | + } |
|
136 | 136 | |
137 | - public function clear() { |
|
138 | - $this->map = array(); |
|
139 | - } |
|
137 | + public function clear() { |
|
138 | + $this->map = array(); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * Register a {@link LoggerRendererObject} for <var>clazz</var>. |
|
143 | - * @param string $class |
|
144 | - * @param LoggerRendererObject $or |
|
145 | - */ |
|
146 | - private function put($class, $or) { |
|
147 | - $this->map[strtolower($class)] = $or; |
|
148 | - } |
|
141 | + /** |
|
142 | + * Register a {@link LoggerRendererObject} for <var>clazz</var>. |
|
143 | + * @param string $class |
|
144 | + * @param LoggerRendererObject $or |
|
145 | + */ |
|
146 | + private function put($class, $or) { |
|
147 | + $this->map[strtolower($class)] = $or; |
|
148 | + } |
|
149 | 149 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * The default Renderer renders objects by type casting. |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | */ |
40 | 40 | class LoggerRendererDefault implements LoggerRendererObject { |
41 | 41 | |
42 | - /** |
|
43 | - * Render objects by type casting |
|
44 | - * |
|
45 | - * @param mixed $o the object to render |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function render($o) { |
|
49 | - return var_export($o, true); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Render objects by type casting |
|
44 | + * |
|
45 | + * @param mixed $o the object to render |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function render($o) { |
|
49 | + return var_export($o, true); |
|
50 | + } |
|
51 | 51 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Implement this interface in order to render objects as strings using {@link LoggerRendererMap}. |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | * @since 0.3 |
38 | 38 | */ |
39 | 39 | interface LoggerRendererObject { |
40 | - /** |
|
41 | - * Render the entity passed as parameter as a String. |
|
42 | - * @param mixed $o entity to render |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function render($o); |
|
40 | + /** |
|
41 | + * Render the entity passed as parameter as a String. |
|
42 | + * @param mixed $o entity to render |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function render($o); |
|
46 | 46 | } |
@@ -48,183 +48,183 @@ |
||
48 | 48 | */ |
49 | 49 | class LoggerAppenderRollingFile extends LoggerAppenderFile { |
50 | 50 | |
51 | - /** |
|
52 | - * Set the maximum size that the output file is allowed to reach |
|
53 | - * before being rolled over to backup files. |
|
54 | - * |
|
55 | - * <p>In configuration files, the <var>MaxFileSize</var> option takes a |
|
56 | - * long integer in the range 0 - 2^63. You can specify the value |
|
57 | - * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
58 | - * interpreted being expressed respectively in kilobytes, megabytes |
|
59 | - * or gigabytes. For example, the value "10KB" will be interpreted |
|
60 | - * as 10240.</p> |
|
61 | - * <p>The default maximum file size is 10MB.</p> |
|
62 | - * |
|
63 | - * <p>Note that MaxFileSize cannot exceed <b>2 GB</b>.</p> |
|
64 | - * |
|
65 | - * @var integer |
|
66 | - */ |
|
67 | - private $maxFileSize = 10485760; |
|
51 | + /** |
|
52 | + * Set the maximum size that the output file is allowed to reach |
|
53 | + * before being rolled over to backup files. |
|
54 | + * |
|
55 | + * <p>In configuration files, the <var>MaxFileSize</var> option takes a |
|
56 | + * long integer in the range 0 - 2^63. You can specify the value |
|
57 | + * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
58 | + * interpreted being expressed respectively in kilobytes, megabytes |
|
59 | + * or gigabytes. For example, the value "10KB" will be interpreted |
|
60 | + * as 10240.</p> |
|
61 | + * <p>The default maximum file size is 10MB.</p> |
|
62 | + * |
|
63 | + * <p>Note that MaxFileSize cannot exceed <b>2 GB</b>.</p> |
|
64 | + * |
|
65 | + * @var integer |
|
66 | + */ |
|
67 | + private $maxFileSize = 10485760; |
|
68 | 68 | |
69 | - /** |
|
70 | - * Set the maximum number of backup files to keep around. |
|
71 | - * |
|
72 | - * <p>The <var>MaxBackupIndex</var> option determines how many backup |
|
73 | - * files are kept before the oldest is erased. This option takes |
|
74 | - * a positive integer value. If set to zero, then there will be no |
|
75 | - * backup files and the log file will be truncated when it reaches |
|
76 | - * MaxFileSize.</p> |
|
77 | - * <p>There is one backup file by default.</p> |
|
78 | - * |
|
79 | - * @var integer |
|
80 | - */ |
|
81 | - private $maxBackupIndex = 1; |
|
69 | + /** |
|
70 | + * Set the maximum number of backup files to keep around. |
|
71 | + * |
|
72 | + * <p>The <var>MaxBackupIndex</var> option determines how many backup |
|
73 | + * files are kept before the oldest is erased. This option takes |
|
74 | + * a positive integer value. If set to zero, then there will be no |
|
75 | + * backup files and the log file will be truncated when it reaches |
|
76 | + * MaxFileSize.</p> |
|
77 | + * <p>There is one backup file by default.</p> |
|
78 | + * |
|
79 | + * @var integer |
|
80 | + */ |
|
81 | + private $maxBackupIndex = 1; |
|
82 | 82 | |
83 | - /** |
|
84 | - * @var string the filename expanded |
|
85 | - * @access private |
|
86 | - */ |
|
87 | - private $expandedFileName = null; |
|
83 | + /** |
|
84 | + * @var string the filename expanded |
|
85 | + * @access private |
|
86 | + */ |
|
87 | + private $expandedFileName = null; |
|
88 | 88 | |
89 | - public function __destruct() { |
|
90 | - parent::__destruct(); |
|
91 | - } |
|
89 | + public function __destruct() { |
|
90 | + parent::__destruct(); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Returns the value of the MaxBackupIndex option. |
|
95 | - * @return integer |
|
96 | - */ |
|
97 | - private function getExpandedFileName() { |
|
98 | - return $this->expandedFileName; |
|
99 | - } |
|
93 | + /** |
|
94 | + * Returns the value of the MaxBackupIndex option. |
|
95 | + * @return integer |
|
96 | + */ |
|
97 | + private function getExpandedFileName() { |
|
98 | + return $this->expandedFileName; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the maximum size that the output file is allowed to reach |
|
103 | - * before being rolled over to backup files. |
|
104 | - * @return integer |
|
105 | - */ |
|
106 | - private function getMaximumFileSize() { |
|
107 | - return $this->maxFileSize; |
|
108 | - } |
|
101 | + /** |
|
102 | + * Get the maximum size that the output file is allowed to reach |
|
103 | + * before being rolled over to backup files. |
|
104 | + * @return integer |
|
105 | + */ |
|
106 | + private function getMaximumFileSize() { |
|
107 | + return $this->maxFileSize; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Implements the usual roll over behaviour. |
|
112 | - * |
|
113 | - * <p>If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex. |
|
114 | - * Moreover, File is renamed File.1 and closed. A new File is created to receive further log output. |
|
115 | - * |
|
116 | - * <p>If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created. |
|
117 | - */ |
|
118 | - private function rollOver() { |
|
119 | - // If maxBackups <= 0, then there is no file renaming to be done. |
|
120 | - if($this->maxBackupIndex > 0) { |
|
121 | - $fileName = $this->getExpandedFileName(); |
|
122 | - // Delete the oldest file, to keep Windows happy. |
|
123 | - $file = $fileName . '.' . $this->maxBackupIndex; |
|
124 | - if(is_writable($file)) |
|
125 | - unlink($file); |
|
126 | - // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} |
|
127 | - for($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { |
|
128 | - $file = $fileName . "." . $i; |
|
129 | - if(is_readable($file)) { |
|
130 | - $target = $fileName . '.' . ($i + 1); |
|
131 | - rename($file, $target); |
|
132 | - } |
|
133 | - } |
|
110 | + /** |
|
111 | + * Implements the usual roll over behaviour. |
|
112 | + * |
|
113 | + * <p>If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex. |
|
114 | + * Moreover, File is renamed File.1 and closed. A new File is created to receive further log output. |
|
115 | + * |
|
116 | + * <p>If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created. |
|
117 | + */ |
|
118 | + private function rollOver() { |
|
119 | + // If maxBackups <= 0, then there is no file renaming to be done. |
|
120 | + if($this->maxBackupIndex > 0) { |
|
121 | + $fileName = $this->getExpandedFileName(); |
|
122 | + // Delete the oldest file, to keep Windows happy. |
|
123 | + $file = $fileName . '.' . $this->maxBackupIndex; |
|
124 | + if(is_writable($file)) |
|
125 | + unlink($file); |
|
126 | + // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} |
|
127 | + for($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { |
|
128 | + $file = $fileName . "." . $i; |
|
129 | + if(is_readable($file)) { |
|
130 | + $target = $fileName . '.' . ($i + 1); |
|
131 | + rename($file, $target); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - $this->close(); |
|
135 | + $this->close(); |
|
136 | 136 | |
137 | - // Rename fileName to fileName.1 |
|
138 | - $target = $fileName . ".1"; |
|
139 | - $file = $fileName; |
|
140 | - rename($file, $target); |
|
141 | - } |
|
137 | + // Rename fileName to fileName.1 |
|
138 | + $target = $fileName . ".1"; |
|
139 | + $file = $fileName; |
|
140 | + rename($file, $target); |
|
141 | + } |
|
142 | 142 | |
143 | - //unset($this->fp); |
|
144 | - $this->activateOptions(); |
|
145 | - $this->setFile($fileName, false); |
|
146 | - } |
|
143 | + //unset($this->fp); |
|
144 | + $this->activateOptions(); |
|
145 | + $this->setFile($fileName, false); |
|
146 | + } |
|
147 | 147 | |
148 | - public function setFileName($fileName) { |
|
149 | - $this->fileName = $fileName; |
|
150 | - // As LoggerAppenderFile does not create the directory, it has to exist. |
|
151 | - // realpath() fails if the argument does not exist so the filename is separated. |
|
152 | - $this->expandedFileName = realpath(dirname($fileName)); |
|
153 | - if ($this->expandedFileName === false) throw new Exception("Directory of $fileName does not exist!"); |
|
154 | - $this->expandedFileName .= '/'.basename($fileName); |
|
155 | - } |
|
148 | + public function setFileName($fileName) { |
|
149 | + $this->fileName = $fileName; |
|
150 | + // As LoggerAppenderFile does not create the directory, it has to exist. |
|
151 | + // realpath() fails if the argument does not exist so the filename is separated. |
|
152 | + $this->expandedFileName = realpath(dirname($fileName)); |
|
153 | + if ($this->expandedFileName === false) throw new Exception("Directory of $fileName does not exist!"); |
|
154 | + $this->expandedFileName .= '/'.basename($fileName); |
|
155 | + } |
|
156 | 156 | |
157 | 157 | |
158 | - /** |
|
159 | - * Set the maximum number of backup files to keep around. |
|
160 | - * |
|
161 | - * <p>The <b>MaxBackupIndex</b> option determines how many backup |
|
162 | - * files are kept before the oldest is erased. This option takes |
|
163 | - * a positive integer value. If set to zero, then there will be no |
|
164 | - * backup files and the log file will be truncated when it reaches |
|
165 | - * MaxFileSize. |
|
166 | - * |
|
167 | - * @param mixed $maxBackups |
|
168 | - */ |
|
169 | - public function setMaxBackupIndex($maxBackups) { |
|
170 | - if(is_numeric($maxBackups)) { |
|
171 | - $this->maxBackupIndex = abs((int)$maxBackups); |
|
172 | - } |
|
173 | - } |
|
158 | + /** |
|
159 | + * Set the maximum number of backup files to keep around. |
|
160 | + * |
|
161 | + * <p>The <b>MaxBackupIndex</b> option determines how many backup |
|
162 | + * files are kept before the oldest is erased. This option takes |
|
163 | + * a positive integer value. If set to zero, then there will be no |
|
164 | + * backup files and the log file will be truncated when it reaches |
|
165 | + * MaxFileSize. |
|
166 | + * |
|
167 | + * @param mixed $maxBackups |
|
168 | + */ |
|
169 | + public function setMaxBackupIndex($maxBackups) { |
|
170 | + if(is_numeric($maxBackups)) { |
|
171 | + $this->maxBackupIndex = abs((int)$maxBackups); |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * Set the maximum size that the output file is allowed to reach |
|
177 | - * before being rolled over to backup files. |
|
178 | - * |
|
179 | - * @param mixed $maxFileSize |
|
180 | - * @see setMaxFileSize() |
|
181 | - * @deprecated |
|
182 | - */ |
|
183 | - public function setMaximumFileSize($maxFileSize) { |
|
184 | - return $this->setMaxFileSize($maxFileSize); |
|
185 | - } |
|
175 | + /** |
|
176 | + * Set the maximum size that the output file is allowed to reach |
|
177 | + * before being rolled over to backup files. |
|
178 | + * |
|
179 | + * @param mixed $maxFileSize |
|
180 | + * @see setMaxFileSize() |
|
181 | + * @deprecated |
|
182 | + */ |
|
183 | + public function setMaximumFileSize($maxFileSize) { |
|
184 | + return $this->setMaxFileSize($maxFileSize); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Set the maximum size that the output file is allowed to reach |
|
189 | - * before being rolled over to backup files. |
|
190 | - * <p>In configuration files, the <b>MaxFileSize</b> option takes an |
|
191 | - * long integer in the range 0 - 2^63. You can specify the value |
|
192 | - * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
193 | - * interpreted being expressed respectively in kilobytes, megabytes |
|
194 | - * or gigabytes. For example, the value "10KB" will be interpreted |
|
195 | - * as 10240. |
|
196 | - * |
|
197 | - * @param mixed $value |
|
198 | - * @return the actual file size set |
|
199 | - */ |
|
200 | - public function setMaxFileSize($value) { |
|
201 | - $maxFileSize = null; |
|
202 | - $numpart = substr($value,0, strlen($value) -2); |
|
203 | - $suffix = strtoupper(substr($value, -2)); |
|
187 | + /** |
|
188 | + * Set the maximum size that the output file is allowed to reach |
|
189 | + * before being rolled over to backup files. |
|
190 | + * <p>In configuration files, the <b>MaxFileSize</b> option takes an |
|
191 | + * long integer in the range 0 - 2^63. You can specify the value |
|
192 | + * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
193 | + * interpreted being expressed respectively in kilobytes, megabytes |
|
194 | + * or gigabytes. For example, the value "10KB" will be interpreted |
|
195 | + * as 10240. |
|
196 | + * |
|
197 | + * @param mixed $value |
|
198 | + * @return the actual file size set |
|
199 | + */ |
|
200 | + public function setMaxFileSize($value) { |
|
201 | + $maxFileSize = null; |
|
202 | + $numpart = substr($value,0, strlen($value) -2); |
|
203 | + $suffix = strtoupper(substr($value, -2)); |
|
204 | 204 | |
205 | - switch($suffix) { |
|
206 | - case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break; |
|
207 | - case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break; |
|
208 | - case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break; |
|
209 | - default: |
|
210 | - if(is_numeric($value)) { |
|
211 | - $maxFileSize = (int)$value; |
|
212 | - } |
|
213 | - } |
|
205 | + switch($suffix) { |
|
206 | + case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break; |
|
207 | + case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break; |
|
208 | + case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break; |
|
209 | + default: |
|
210 | + if(is_numeric($value)) { |
|
211 | + $maxFileSize = (int)$value; |
|
212 | + } |
|
213 | + } |
|
214 | 214 | |
215 | - if($maxFileSize !== null) { |
|
216 | - $this->maxFileSize = abs($maxFileSize); |
|
217 | - } |
|
218 | - return $this->maxFileSize; |
|
219 | - } |
|
215 | + if($maxFileSize !== null) { |
|
216 | + $this->maxFileSize = abs($maxFileSize); |
|
217 | + } |
|
218 | + return $this->maxFileSize; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * @param LoggerLoggingEvent $event |
|
223 | - */ |
|
224 | - public function append(LoggerLoggingEvent $event) { |
|
225 | - parent::append($event); |
|
226 | - if(ftell($this->fp) > $this->getMaximumFileSize()) { |
|
227 | - $this->rollOver(); |
|
228 | - } |
|
229 | - } |
|
221 | + /** |
|
222 | + * @param LoggerLoggingEvent $event |
|
223 | + */ |
|
224 | + public function append(LoggerLoggingEvent $event) { |
|
225 | + parent::append($event); |
|
226 | + if(ftell($this->fp) > $this->getMaximumFileSize()) { |
|
227 | + $this->rollOver(); |
|
228 | + } |
|
229 | + } |
|
230 | 230 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * ConsoleAppender appends log events to STDOUT or STDERR. |
@@ -43,70 +43,70 @@ discard block |
||
43 | 43 | */ |
44 | 44 | class LoggerAppenderConsole extends LoggerAppender { |
45 | 45 | |
46 | - const STDOUT = 'php://stdout'; |
|
47 | - const STDERR = 'php://stderr'; |
|
46 | + const STDOUT = 'php://stdout'; |
|
47 | + const STDERR = 'php://stderr'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Can be 'php://stdout' or 'php://stderr'. But it's better to use keywords <b>STDOUT</b> and <b>STDERR</b> (case insensitive). |
|
51 | - * Default is STDOUT |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - private $target = self::STDOUT; |
|
49 | + /** |
|
50 | + * Can be 'php://stdout' or 'php://stderr'. But it's better to use keywords <b>STDOUT</b> and <b>STDERR</b> (case insensitive). |
|
51 | + * Default is STDOUT |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + private $target = self::STDOUT; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var boolean |
|
58 | - * @access private |
|
59 | - */ |
|
60 | - protected $requiresLayout = true; |
|
56 | + /** |
|
57 | + * @var boolean |
|
58 | + * @access private |
|
59 | + */ |
|
60 | + protected $requiresLayout = true; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var mixed the resource used to open stdout/stderr |
|
64 | - * @access private |
|
65 | - */ |
|
66 | - protected $fp = null; |
|
62 | + /** |
|
63 | + * @var mixed the resource used to open stdout/stderr |
|
64 | + * @access private |
|
65 | + */ |
|
66 | + protected $fp = null; |
|
67 | 67 | |
68 | - public function __destruct() { |
|
69 | - $this->close(); |
|
70 | - } |
|
68 | + public function __destruct() { |
|
69 | + $this->close(); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Set console target. |
|
74 | - * @param mixed $value a constant or a string |
|
75 | - */ |
|
76 | - public function setTarget($value) { |
|
77 | - $v = trim($value); |
|
78 | - if ($v == self::STDOUT || strtoupper($v) == 'STDOUT') { |
|
79 | - $this->target = self::STDOUT; |
|
80 | - } elseif ($v == self::STDERR || strtoupper($v) == 'STDERR') { |
|
81 | - $this->target = self::STDERR; |
|
82 | - } |
|
83 | - } |
|
72 | + /** |
|
73 | + * Set console target. |
|
74 | + * @param mixed $value a constant or a string |
|
75 | + */ |
|
76 | + public function setTarget($value) { |
|
77 | + $v = trim($value); |
|
78 | + if ($v == self::STDOUT || strtoupper($v) == 'STDOUT') { |
|
79 | + $this->target = self::STDOUT; |
|
80 | + } elseif ($v == self::STDERR || strtoupper($v) == 'STDERR') { |
|
81 | + $this->target = self::STDERR; |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - public function activateOptions() { |
|
86 | - $this->fp = fopen($this->target, 'w'); |
|
87 | - if(is_resource($this->fp) && $this->layout !== null) { |
|
88 | - fwrite($this->fp, $this->layout->getHeader()); |
|
89 | - } |
|
90 | - $this->closed = (bool)is_resource($this->fp) === false; |
|
91 | - } |
|
85 | + public function activateOptions() { |
|
86 | + $this->fp = fopen($this->target, 'w'); |
|
87 | + if(is_resource($this->fp) && $this->layout !== null) { |
|
88 | + fwrite($this->fp, $this->layout->getHeader()); |
|
89 | + } |
|
90 | + $this->closed = (bool)is_resource($this->fp) === false; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @see LoggerAppender::close() |
|
95 | - */ |
|
96 | - public function close() { |
|
97 | - if($this->closed != true) { |
|
98 | - if (is_resource($this->fp) && $this->layout !== null) { |
|
99 | - fwrite($this->fp, $this->layout->getFooter()); |
|
100 | - fclose($this->fp); |
|
101 | - } |
|
102 | - $this->closed = true; |
|
103 | - } |
|
104 | - } |
|
93 | + /** |
|
94 | + * @see LoggerAppender::close() |
|
95 | + */ |
|
96 | + public function close() { |
|
97 | + if($this->closed != true) { |
|
98 | + if (is_resource($this->fp) && $this->layout !== null) { |
|
99 | + fwrite($this->fp, $this->layout->getFooter()); |
|
100 | + fclose($this->fp); |
|
101 | + } |
|
102 | + $this->closed = true; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - public function append(LoggerLoggingEvent $event) { |
|
107 | - if (is_resource($this->fp) && $this->layout !== null) { |
|
108 | - fwrite($this->fp, $this->layout->format($event)); |
|
109 | - } |
|
110 | - } |
|
106 | + public function append(LoggerLoggingEvent $event) { |
|
107 | + if (is_resource($this->fp) && $this->layout !== null) { |
|
108 | + fwrite($this->fp, $this->layout->format($event)); |
|
109 | + } |
|
110 | + } |
|
111 | 111 | } |
112 | 112 |
@@ -53,57 +53,57 @@ discard block |
||
53 | 53 | */ |
54 | 54 | class LoggerAppenderMailEvent extends LoggerAppender { |
55 | 55 | |
56 | - /** 'from' field (defaults to 'sendmail_from' from php.ini on win32). |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - private $from = null; |
|
56 | + /** 'from' field (defaults to 'sendmail_from' from php.ini on win32). |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + private $from = null; |
|
60 | 60 | |
61 | - /** Mailserver port (win32 only). |
|
62 | - * @var integer |
|
63 | - */ |
|
64 | - private $port = 25; |
|
61 | + /** Mailserver port (win32 only). |
|
62 | + * @var integer |
|
63 | + */ |
|
64 | + private $port = 25; |
|
65 | 65 | |
66 | - /** Mailserver hostname (win32 only). |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - private $smtpHost = null; |
|
66 | + /** Mailserver hostname (win32 only). |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + private $smtpHost = null; |
|
70 | 70 | |
71 | - /** |
|
72 | - * @var string 'subject' field |
|
73 | - */ |
|
74 | - private $subject = ''; |
|
71 | + /** |
|
72 | + * @var string 'subject' field |
|
73 | + */ |
|
74 | + private $subject = ''; |
|
75 | 75 | |
76 | - /** |
|
77 | - * @var string 'to' field |
|
78 | - */ |
|
79 | - private $to = null; |
|
76 | + /** |
|
77 | + * @var string 'to' field |
|
78 | + */ |
|
79 | + private $to = null; |
|
80 | 80 | |
81 | - /** |
|
82 | - * @access private |
|
83 | - */ |
|
84 | - protected $requiresLayout = true; |
|
81 | + /** |
|
82 | + * @access private |
|
83 | + */ |
|
84 | + protected $requiresLayout = true; |
|
85 | 85 | |
86 | - /** @var indiciates if this appender should run in dry mode */ |
|
87 | - private $dry = false; |
|
86 | + /** @var indiciates if this appender should run in dry mode */ |
|
87 | + private $dry = false; |
|
88 | 88 | |
89 | - /** |
|
90 | - * Constructor. |
|
91 | - * |
|
92 | - * @param string $name appender name |
|
93 | - */ |
|
94 | - public function __construct($name = '') { |
|
95 | - parent::__construct($name); |
|
96 | - } |
|
89 | + /** |
|
90 | + * Constructor. |
|
91 | + * |
|
92 | + * @param string $name appender name |
|
93 | + */ |
|
94 | + public function __construct($name = '') { |
|
95 | + parent::__construct($name); |
|
96 | + } |
|
97 | 97 | |
98 | - public function __destruct() { |
|
99 | - $this->close(); |
|
100 | - } |
|
98 | + public function __destruct() { |
|
99 | + $this->close(); |
|
100 | + } |
|
101 | 101 | |
102 | - public function activateOptions() { |
|
103 | - if (empty($this->layout)) { |
|
104 | - throw new LoggerException("LoggerAppenderMailEvent requires layout!"); |
|
105 | - } |
|
106 | - if (empty($this->to)) { |
|
102 | + public function activateOptions() { |
|
103 | + if (empty($this->layout)) { |
|
104 | + throw new LoggerException("LoggerAppenderMailEvent requires layout!"); |
|
105 | + } |
|
106 | + if (empty($this->to)) { |
|
107 | 107 | throw new LoggerException("LoggerAppenderMailEvent was initialized with empty 'from' ($this->from) or 'to' ($this->to) Adress!"); |
108 | 108 | } |
109 | 109 | |
@@ -113,67 +113,67 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | $this->closed = false; |
116 | - } |
|
116 | + } |
|
117 | 117 | |
118 | - public function close() { |
|
119 | - $this->closed = true; |
|
120 | - } |
|
118 | + public function close() { |
|
119 | + $this->closed = true; |
|
120 | + } |
|
121 | 121 | |
122 | - public function setFrom($from) { |
|
123 | - $this->from = $from; |
|
124 | - } |
|
122 | + public function setFrom($from) { |
|
123 | + $this->from = $from; |
|
124 | + } |
|
125 | 125 | |
126 | - public function setPort($port) { |
|
127 | - $this->port = (int)$port; |
|
128 | - } |
|
126 | + public function setPort($port) { |
|
127 | + $this->port = (int)$port; |
|
128 | + } |
|
129 | 129 | |
130 | - public function setSmtpHost($smtpHost) { |
|
131 | - $this->smtpHost = $smtpHost; |
|
132 | - } |
|
130 | + public function setSmtpHost($smtpHost) { |
|
131 | + $this->smtpHost = $smtpHost; |
|
132 | + } |
|
133 | 133 | |
134 | - public function setSubject($subject) { |
|
135 | - $this->subject = $subject; |
|
136 | - } |
|
134 | + public function setSubject($subject) { |
|
135 | + $this->subject = $subject; |
|
136 | + } |
|
137 | 137 | |
138 | - public function setTo($to) { |
|
139 | - $this->to = $to; |
|
140 | - } |
|
138 | + public function setTo($to) { |
|
139 | + $this->to = $to; |
|
140 | + } |
|
141 | 141 | |
142 | - public function setDry($dry) { |
|
143 | - $this->dry = $dry; |
|
144 | - } |
|
142 | + public function setDry($dry) { |
|
143 | + $this->dry = $dry; |
|
144 | + } |
|
145 | 145 | |
146 | - public function append(LoggerLoggingEvent $event) { |
|
147 | - $smtpHost = $this->smtpHost; |
|
148 | - $prevSmtpHost = ini_get('SMTP'); |
|
149 | - if(!empty($smtpHost)) { |
|
150 | - ini_set('SMTP', $smtpHost); |
|
151 | - } |
|
146 | + public function append(LoggerLoggingEvent $event) { |
|
147 | + $smtpHost = $this->smtpHost; |
|
148 | + $prevSmtpHost = ini_get('SMTP'); |
|
149 | + if(!empty($smtpHost)) { |
|
150 | + ini_set('SMTP', $smtpHost); |
|
151 | + } |
|
152 | 152 | |
153 | - $smtpPort = $this->port; |
|
154 | - $prevSmtpPort= ini_get('smtp_port'); |
|
155 | - if($smtpPort > 0 and $smtpPort < 65535) { |
|
156 | - ini_set('smtp_port', $smtpPort); |
|
157 | - } |
|
153 | + $smtpPort = $this->port; |
|
154 | + $prevSmtpPort= ini_get('smtp_port'); |
|
155 | + if($smtpPort > 0 and $smtpPort < 65535) { |
|
156 | + ini_set('smtp_port', $smtpPort); |
|
157 | + } |
|
158 | 158 | |
159 | - // On unix only sendmail_path, which is PHP_INI_SYSTEM i.e. not changeable here, is used. |
|
159 | + // On unix only sendmail_path, which is PHP_INI_SYSTEM i.e. not changeable here, is used. |
|
160 | 160 | |
161 | - $addHeader = empty($this->from) ? '' : "From: {$this->from}\r\n"; |
|
161 | + $addHeader = empty($this->from) ? '' : "From: {$this->from}\r\n"; |
|
162 | 162 | |
163 | - if(!$this->dry) { |
|
164 | - $result = mail($this->to, $this->subject, |
|
165 | - $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event), |
|
166 | - $addHeader); |
|
167 | - if ($result === false) { |
|
168 | - // The error message is only printed to stderr as warning. Any idea how to get it? |
|
169 | - throw new LoggerException("Error sending mail to '".$this->to."'!"); |
|
170 | - } |
|
171 | - } else { |
|
172 | - echo "DRY MODE OF MAIL APP.: Send mail to: ".$this->to." with additional headers '".trim($addHeader)."' and content: ".$this->layout->format($event); |
|
173 | - } |
|
163 | + if(!$this->dry) { |
|
164 | + $result = mail($this->to, $this->subject, |
|
165 | + $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event), |
|
166 | + $addHeader); |
|
167 | + if ($result === false) { |
|
168 | + // The error message is only printed to stderr as warning. Any idea how to get it? |
|
169 | + throw new LoggerException("Error sending mail to '".$this->to."'!"); |
|
170 | + } |
|
171 | + } else { |
|
172 | + echo "DRY MODE OF MAIL APP.: Send mail to: ".$this->to." with additional headers '".trim($addHeader)."' and content: ".$this->layout->format($event); |
|
173 | + } |
|
174 | 174 | |
175 | - ini_set('SMTP', $prevSmtpHost); |
|
176 | - ini_set('smtp_port', $prevSmtpPort); |
|
177 | - } |
|
175 | + ini_set('SMTP', $prevSmtpHost); |
|
176 | + ini_set('smtp_port', $prevSmtpPort); |
|
177 | + } |
|
178 | 178 | } |
179 | 179 |
@@ -121,10 +121,10 @@ |
||
121 | 121 | { |
122 | 122 | $this->db = &ADONewConnection($this->type); |
123 | 123 | if (! $this->db->PConnect($this->host, $this->user, $this->password, $this->database)) { |
124 | - $this->db = null; |
|
125 | - $this->closed = true; |
|
126 | - $this->canAppend = false; |
|
127 | - return; |
|
124 | + $this->db = null; |
|
125 | + $this->closed = true; |
|
126 | + $this->canAppend = false; |
|
127 | + return; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | $this->layout = LoggerReflectionUtils::createObject('LoggerLayoutPattern'); |