@@ -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 | * Appends log events to mail using php function {@link PHP_MANUAL#mail}. |
@@ -47,85 +47,84 @@ discard block |
||
47 | 47 | * Tue Sep 8 21:51:04 2009,120 [5485] FATAL root - Some critical message! |
48 | 48 | * Tue Sep 8 21:51:06 2009,120 [5485] FATAL root - Some more critical message! |
49 | 49 | * </pre> |
50 | - |
|
51 | 50 | * @version $Revision: 883108 $ |
52 | 51 | * @package log4php |
53 | 52 | * @subpackage appenders |
54 | 53 | */ |
55 | 54 | class LoggerAppenderMail extends LoggerAppender { |
56 | 55 | |
57 | - /** @var string 'from' field */ |
|
58 | - private $from = null; |
|
56 | + /** @var string 'from' field */ |
|
57 | + private $from = null; |
|
59 | 58 | |
60 | - /** @var string 'subject' field */ |
|
61 | - private $subject = 'Log4php Report'; |
|
59 | + /** @var string 'subject' field */ |
|
60 | + private $subject = 'Log4php Report'; |
|
62 | 61 | |
63 | - /** @var string 'to' field */ |
|
64 | - private $to = null; |
|
62 | + /** @var string 'to' field */ |
|
63 | + private $to = null; |
|
65 | 64 | |
66 | - /** @var indiciates if this appender should run in dry mode */ |
|
67 | - private $dry = false; |
|
65 | + /** @var indiciates if this appender should run in dry mode */ |
|
66 | + private $dry = false; |
|
68 | 67 | |
69 | - /** @var string used to create mail body */ |
|
70 | - private $body = ''; |
|
68 | + /** @var string used to create mail body */ |
|
69 | + private $body = ''; |
|
71 | 70 | |
72 | - /** |
|
73 | - * Constructor. |
|
74 | - * |
|
75 | - * @param string $name appender name |
|
76 | - */ |
|
77 | - public function __construct($name = '') { |
|
78 | - parent::__construct($name); |
|
79 | - $this->requiresLayout = true; |
|
80 | - } |
|
71 | + /** |
|
72 | + * Constructor. |
|
73 | + * |
|
74 | + * @param string $name appender name |
|
75 | + */ |
|
76 | + public function __construct($name = '') { |
|
77 | + parent::__construct($name); |
|
78 | + $this->requiresLayout = true; |
|
79 | + } |
|
81 | 80 | |
82 | - public function __destruct() { |
|
83 | - $this->close(); |
|
84 | - } |
|
81 | + public function __destruct() { |
|
82 | + $this->close(); |
|
83 | + } |
|
85 | 84 | |
86 | - public function activateOptions() { |
|
87 | - $this->closed = false; |
|
88 | - } |
|
85 | + public function activateOptions() { |
|
86 | + $this->closed = false; |
|
87 | + } |
|
89 | 88 | |
90 | - public function close() { |
|
91 | - if($this->closed != true) { |
|
92 | - $from = $this->from; |
|
93 | - $to = $this->to; |
|
89 | + public function close() { |
|
90 | + if($this->closed != true) { |
|
91 | + $from = $this->from; |
|
92 | + $to = $this->to; |
|
94 | 93 | |
95 | - if(!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) { |
|
96 | - $subject = $this->subject; |
|
97 | - if(!$this->dry) { |
|
98 | - mail( |
|
99 | - $to, $subject, |
|
100 | - $this->layout->getHeader() . $this->body . $this->layout->getFooter(), |
|
101 | - "From: {$from}\r\n"); |
|
102 | - } else { |
|
103 | - echo "DRY MODE OF MAIL APP.: Send mail to: ".$to." with content: ".$this->body; |
|
104 | - } |
|
105 | - } |
|
106 | - $this->closed = true; |
|
107 | - } |
|
108 | - } |
|
94 | + if(!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) { |
|
95 | + $subject = $this->subject; |
|
96 | + if(!$this->dry) { |
|
97 | + mail( |
|
98 | + $to, $subject, |
|
99 | + $this->layout->getHeader() . $this->body . $this->layout->getFooter(), |
|
100 | + "From: {$from}\r\n"); |
|
101 | + } else { |
|
102 | + echo "DRY MODE OF MAIL APP.: Send mail to: ".$to." with content: ".$this->body; |
|
103 | + } |
|
104 | + } |
|
105 | + $this->closed = true; |
|
106 | + } |
|
107 | + } |
|
109 | 108 | |
110 | - public function setSubject($subject) { |
|
111 | - $this->subject = $subject; |
|
112 | - } |
|
109 | + public function setSubject($subject) { |
|
110 | + $this->subject = $subject; |
|
111 | + } |
|
113 | 112 | |
114 | - public function setTo($to) { |
|
115 | - $this->to = $to; |
|
116 | - } |
|
113 | + public function setTo($to) { |
|
114 | + $this->to = $to; |
|
115 | + } |
|
117 | 116 | |
118 | - public function setFrom($from) { |
|
119 | - $this->from = $from; |
|
120 | - } |
|
117 | + public function setFrom($from) { |
|
118 | + $this->from = $from; |
|
119 | + } |
|
121 | 120 | |
122 | - public function setDry($dry) { |
|
123 | - $this->dry = $dry; |
|
124 | - } |
|
121 | + public function setDry($dry) { |
|
122 | + $this->dry = $dry; |
|
123 | + } |
|
125 | 124 | |
126 | - public function append(LoggerLoggingEvent $event) { |
|
127 | - if($this->layout !== null) { |
|
128 | - $this->body .= $this->layout->format($event); |
|
129 | - } |
|
130 | - } |
|
125 | + public function append(LoggerLoggingEvent $event) { |
|
126 | + if($this->layout !== null) { |
|
127 | + $this->body .= $this->layout->format($event); |
|
128 | + } |
|
129 | + } |
|
131 | 130 | } |
@@ -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 | * FileAppender appends log events to a file. |
@@ -42,129 +42,129 @@ discard block |
||
42 | 42 | */ |
43 | 43 | class LoggerAppenderFile extends LoggerAppender { |
44 | 44 | |
45 | - /** |
|
46 | - * @var boolean if {@link $file} exists, appends events. |
|
47 | - */ |
|
48 | - private $append = true; |
|
49 | - /** |
|
50 | - * @var string the file name used to append events |
|
51 | - */ |
|
52 | - protected $fileName; |
|
53 | - /** |
|
54 | - * @var mixed file resource |
|
55 | - */ |
|
56 | - protected $fp = false; |
|
45 | + /** |
|
46 | + * @var boolean if {@link $file} exists, appends events. |
|
47 | + */ |
|
48 | + private $append = true; |
|
49 | + /** |
|
50 | + * @var string the file name used to append events |
|
51 | + */ |
|
52 | + protected $fileName; |
|
53 | + /** |
|
54 | + * @var mixed file resource |
|
55 | + */ |
|
56 | + protected $fp = false; |
|
57 | 57 | |
58 | - public function __construct($name = '') { |
|
59 | - parent::__construct($name); |
|
60 | - $this->requiresLayout = true; |
|
61 | - } |
|
58 | + public function __construct($name = '') { |
|
59 | + parent::__construct($name); |
|
60 | + $this->requiresLayout = true; |
|
61 | + } |
|
62 | 62 | |
63 | - public function __destruct() { |
|
64 | - $this->close(); |
|
65 | - } |
|
63 | + public function __destruct() { |
|
64 | + $this->close(); |
|
65 | + } |
|
66 | 66 | |
67 | - public function activateOptions() { |
|
68 | - $fileName = $this->getFile(); |
|
67 | + public function activateOptions() { |
|
68 | + $fileName = $this->getFile(); |
|
69 | 69 | |
70 | - if(!is_file($fileName)) { |
|
71 | - $dir = dirname($fileName); |
|
72 | - if(!is_dir($dir)) { |
|
73 | - mkdir($dir, 0777, true); |
|
74 | - } |
|
75 | - } |
|
70 | + if(!is_file($fileName)) { |
|
71 | + $dir = dirname($fileName); |
|
72 | + if(!is_dir($dir)) { |
|
73 | + mkdir($dir, 0777, true); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
78 | - if($this->fp) { |
|
79 | - if(flock($this->fp, LOCK_EX)) { |
|
80 | - if($this->getAppend()) { |
|
81 | - fseek($this->fp, 0, SEEK_END); |
|
82 | - } |
|
83 | - fwrite($this->fp, $this->layout->getHeader()); |
|
84 | - flock($this->fp, LOCK_UN); |
|
85 | - $this->closed = false; |
|
86 | - } else { |
|
87 | - // TODO: should we take some action in this case? |
|
88 | - $this->closed = true; |
|
89 | - } |
|
90 | - } else { |
|
91 | - $this->closed = true; |
|
92 | - } |
|
93 | - } |
|
77 | + $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
78 | + if($this->fp) { |
|
79 | + if(flock($this->fp, LOCK_EX)) { |
|
80 | + if($this->getAppend()) { |
|
81 | + fseek($this->fp, 0, SEEK_END); |
|
82 | + } |
|
83 | + fwrite($this->fp, $this->layout->getHeader()); |
|
84 | + flock($this->fp, LOCK_UN); |
|
85 | + $this->closed = false; |
|
86 | + } else { |
|
87 | + // TODO: should we take some action in this case? |
|
88 | + $this->closed = true; |
|
89 | + } |
|
90 | + } else { |
|
91 | + $this->closed = true; |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - public function close() { |
|
96 | - if($this->closed != true) { |
|
97 | - if($this->fp and $this->layout !== null) { |
|
98 | - if(flock($this->fp, LOCK_EX)) { |
|
99 | - fwrite($this->fp, $this->layout->getFooter()); |
|
100 | - flock($this->fp, LOCK_UN); |
|
101 | - } |
|
102 | - fclose($this->fp); |
|
103 | - } |
|
104 | - $this->closed = true; |
|
105 | - } |
|
106 | - } |
|
95 | + public function close() { |
|
96 | + if($this->closed != true) { |
|
97 | + if($this->fp and $this->layout !== null) { |
|
98 | + if(flock($this->fp, LOCK_EX)) { |
|
99 | + fwrite($this->fp, $this->layout->getFooter()); |
|
100 | + flock($this->fp, LOCK_UN); |
|
101 | + } |
|
102 | + fclose($this->fp); |
|
103 | + } |
|
104 | + $this->closed = true; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - public function append(LoggerLoggingEvent $event) { |
|
109 | - if($this->fp and $this->layout !== null) { |
|
110 | - if(flock($this->fp, LOCK_EX)) { |
|
111 | - fwrite($this->fp, $this->layout->format($event)); |
|
112 | - flock($this->fp, LOCK_UN); |
|
113 | - } else { |
|
114 | - $this->closed = true; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
108 | + public function append(LoggerLoggingEvent $event) { |
|
109 | + if($this->fp and $this->layout !== null) { |
|
110 | + if(flock($this->fp, LOCK_EX)) { |
|
111 | + fwrite($this->fp, $this->layout->format($event)); |
|
112 | + flock($this->fp, LOCK_UN); |
|
113 | + } else { |
|
114 | + $this->closed = true; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Sets and opens the file where the log output will go. |
|
121 | - * |
|
122 | - * This is an overloaded method. It can be called with: |
|
123 | - * - setFile(string $fileName) to set filename. |
|
124 | - * - setFile(string $fileName, boolean $append) to set filename and append. |
|
125 | - * |
|
126 | - * TODO: remove overloading. Use only file as alias to filename |
|
127 | - */ |
|
128 | - public function setFile() { |
|
129 | - $numargs = func_num_args(); |
|
130 | - $args = func_get_args(); |
|
119 | + /** |
|
120 | + * Sets and opens the file where the log output will go. |
|
121 | + * |
|
122 | + * This is an overloaded method. It can be called with: |
|
123 | + * - setFile(string $fileName) to set filename. |
|
124 | + * - setFile(string $fileName, boolean $append) to set filename and append. |
|
125 | + * |
|
126 | + * TODO: remove overloading. Use only file as alias to filename |
|
127 | + */ |
|
128 | + public function setFile() { |
|
129 | + $numargs = func_num_args(); |
|
130 | + $args = func_get_args(); |
|
131 | 131 | |
132 | - if($numargs == 1 and is_string($args[0])) { |
|
133 | - $this->setFileName($args[0]); |
|
134 | - } else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { |
|
135 | - $this->setFile($args[0]); |
|
136 | - $this->setAppend($args[1]); |
|
137 | - } |
|
138 | - } |
|
132 | + if($numargs == 1 and is_string($args[0])) { |
|
133 | + $this->setFileName($args[0]); |
|
134 | + } else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { |
|
135 | + $this->setFile($args[0]); |
|
136 | + $this->setAppend($args[1]); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function getFile() { |
|
144 | - return $this->getFileName(); |
|
145 | - } |
|
140 | + /** |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function getFile() { |
|
144 | + return $this->getFileName(); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @return boolean |
|
149 | - */ |
|
150 | - public function getAppend() { |
|
151 | - return $this->append; |
|
152 | - } |
|
147 | + /** |
|
148 | + * @return boolean |
|
149 | + */ |
|
150 | + public function getAppend() { |
|
151 | + return $this->append; |
|
152 | + } |
|
153 | 153 | |
154 | - public function setAppend($flag) { |
|
155 | - $this->append = LoggerOptionConverter::toBoolean($flag, true); |
|
156 | - } |
|
154 | + public function setAppend($flag) { |
|
155 | + $this->append = LoggerOptionConverter::toBoolean($flag, true); |
|
156 | + } |
|
157 | 157 | |
158 | - public function setFileName($fileName) { |
|
159 | - $this->fileName = $fileName; |
|
160 | - } |
|
158 | + public function setFileName($fileName) { |
|
159 | + $this->fileName = $fileName; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function getFileName() { |
|
166 | - return $this->fileName; |
|
167 | - } |
|
162 | + /** |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function getFileName() { |
|
166 | + return $this->fileName; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | |
170 | 170 | } |
@@ -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'); |
@@ -40,33 +40,33 @@ |
||
40 | 40 | */ |
41 | 41 | class LoggerAppenderPhp extends LoggerAppender { |
42 | 42 | |
43 | - public function __construct($name = '') { |
|
44 | - parent::__construct($name); |
|
45 | - $this->requiresLayout = true; |
|
46 | - } |
|
43 | + public function __construct($name = '') { |
|
44 | + parent::__construct($name); |
|
45 | + $this->requiresLayout = true; |
|
46 | + } |
|
47 | 47 | |
48 | - public function __destruct() { |
|
49 | - $this->close(); |
|
50 | - } |
|
48 | + public function __destruct() { |
|
49 | + $this->close(); |
|
50 | + } |
|
51 | 51 | |
52 | - public function activateOptions() { |
|
53 | - $this->closed = false; |
|
54 | - } |
|
52 | + public function activateOptions() { |
|
53 | + $this->closed = false; |
|
54 | + } |
|
55 | 55 | |
56 | - public function close() { |
|
57 | - $this->closed = true; |
|
58 | - } |
|
56 | + public function close() { |
|
57 | + $this->closed = true; |
|
58 | + } |
|
59 | 59 | |
60 | - public function append(LoggerLoggingEvent $event) { |
|
61 | - if($this->layout !== null) { |
|
62 | - $level = $event->getLevel(); |
|
63 | - if($level->isGreaterOrEqual(LoggerLevel::getLevelError())) { |
|
64 | - trigger_error($this->layout->format($event), E_USER_ERROR); |
|
65 | - } else if ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) { |
|
66 | - trigger_error($this->layout->format($event), E_USER_WARNING); |
|
67 | - } else { |
|
68 | - trigger_error($this->layout->format($event), E_USER_NOTICE); |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
60 | + public function append(LoggerLoggingEvent $event) { |
|
61 | + if($this->layout !== null) { |
|
62 | + $level = $event->getLevel(); |
|
63 | + if($level->isGreaterOrEqual(LoggerLevel::getLevelError())) { |
|
64 | + trigger_error($this->layout->format($event), E_USER_ERROR); |
|
65 | + } else if ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) { |
|
66 | + trigger_error($this->layout->format($event), E_USER_WARNING); |
|
67 | + } else { |
|
68 | + trigger_error($this->layout->format($event), E_USER_NOTICE); |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -46,215 +46,215 @@ |
||
46 | 46 | */ |
47 | 47 | class LoggerAppenderSocket extends LoggerAppender { |
48 | 48 | |
49 | - /** |
|
50 | - * @var mixed socket connection resource |
|
51 | - * @access private |
|
52 | - */ |
|
53 | - private $sp = false; |
|
49 | + /** |
|
50 | + * @var mixed socket connection resource |
|
51 | + * @access private |
|
52 | + */ |
|
53 | + private $sp = false; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Target host. On how to define remote hostaname see |
|
57 | - * {@link PHP_MANUAL#fsockopen} |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - private $remoteHost = ''; |
|
55 | + /** |
|
56 | + * Target host. On how to define remote hostaname see |
|
57 | + * {@link PHP_MANUAL#fsockopen} |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + private $remoteHost = ''; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var integer the network port. |
|
64 | - */ |
|
65 | - private $port = 4446; |
|
62 | + /** |
|
63 | + * @var integer the network port. |
|
64 | + */ |
|
65 | + private $port = 4446; |
|
66 | 66 | |
67 | - /** |
|
68 | - * @var boolean get event's location info. |
|
69 | - */ |
|
70 | - private $locationInfo = false; |
|
67 | + /** |
|
68 | + * @var boolean get event's location info. |
|
69 | + */ |
|
70 | + private $locationInfo = false; |
|
71 | 71 | |
72 | - /** |
|
73 | - * @var integer connection timeout |
|
74 | - */ |
|
75 | - private $timeout = 30; |
|
72 | + /** |
|
73 | + * @var integer connection timeout |
|
74 | + */ |
|
75 | + private $timeout = 30; |
|
76 | 76 | |
77 | - /** |
|
78 | - * @var boolean output events via {@link LoggerXmlLayout} |
|
79 | - */ |
|
80 | - private $useXml = false; |
|
77 | + /** |
|
78 | + * @var boolean output events via {@link LoggerXmlLayout} |
|
79 | + */ |
|
80 | + private $useXml = false; |
|
81 | 81 | |
82 | - /** |
|
83 | - * @var boolean forward this option to {@link LoggerXmlLayout}. |
|
84 | - * Ignored if {@link $useXml} is <i>false</i>. |
|
85 | - */ |
|
86 | - private $log4jNamespace = false; |
|
82 | + /** |
|
83 | + * @var boolean forward this option to {@link LoggerXmlLayout}. |
|
84 | + * Ignored if {@link $useXml} is <i>false</i>. |
|
85 | + */ |
|
86 | + private $log4jNamespace = false; |
|
87 | 87 | |
88 | - /** |
|
89 | - * @var LoggerXmlLayout |
|
90 | - * @access private |
|
91 | - */ |
|
92 | - private $xmlLayout = null; |
|
88 | + /** |
|
89 | + * @var LoggerXmlLayout |
|
90 | + * @access private |
|
91 | + */ |
|
92 | + private $xmlLayout = null; |
|
93 | 93 | |
94 | - /** @var indiciates if this appender should run in dry mode */ |
|
95 | - private $dry = false; |
|
94 | + /** @var indiciates if this appender should run in dry mode */ |
|
95 | + private $dry = false; |
|
96 | 96 | |
97 | - public function __destruct() { |
|
98 | - $this->close(); |
|
99 | - } |
|
97 | + public function __destruct() { |
|
98 | + $this->close(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Create a socket connection using defined parameters |
|
103 | - */ |
|
104 | - public function activateOptions() { |
|
105 | - if(!$this->dry) { |
|
106 | - $this->sp = @fsockopen($this->getRemoteHost(), $this->getPort(), $errno, $errstr, $this->getTimeout()); |
|
107 | - if ($this->sp === false) { |
|
108 | - throw new LoggerException("Could not open socket to ".$this->getRemoteHost().":".$this->getPort().": $errstr ($errno)"); |
|
109 | - } |
|
110 | - } |
|
111 | - if($this->getUseXml()) { |
|
112 | - $this->xmlLayout = LoggerReflectionUtils::createObject('LoggerLayoutXml'); |
|
113 | - if($this->xmlLayout === null) { |
|
114 | - $this->setUseXml(false); |
|
115 | - } else { |
|
116 | - $this->xmlLayout->setLocationInfo($this->getLocationInfo()); |
|
117 | - $this->xmlLayout->setLog4jNamespace($this->getLog4jNamespace()); |
|
118 | - $this->xmlLayout->activateOptions(); |
|
119 | - } |
|
120 | - } |
|
101 | + /** |
|
102 | + * Create a socket connection using defined parameters |
|
103 | + */ |
|
104 | + public function activateOptions() { |
|
105 | + if(!$this->dry) { |
|
106 | + $this->sp = @fsockopen($this->getRemoteHost(), $this->getPort(), $errno, $errstr, $this->getTimeout()); |
|
107 | + if ($this->sp === false) { |
|
108 | + throw new LoggerException("Could not open socket to ".$this->getRemoteHost().":".$this->getPort().": $errstr ($errno)"); |
|
109 | + } |
|
110 | + } |
|
111 | + if($this->getUseXml()) { |
|
112 | + $this->xmlLayout = LoggerReflectionUtils::createObject('LoggerLayoutXml'); |
|
113 | + if($this->xmlLayout === null) { |
|
114 | + $this->setUseXml(false); |
|
115 | + } else { |
|
116 | + $this->xmlLayout->setLocationInfo($this->getLocationInfo()); |
|
117 | + $this->xmlLayout->setLog4jNamespace($this->getLog4jNamespace()); |
|
118 | + $this->xmlLayout->activateOptions(); |
|
119 | + } |
|
120 | + } |
|
121 | 121 | $this->closed = false; |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - public function close() { |
|
125 | - if($this->closed != true) { |
|
126 | - if(!$this->dry and $this->sp !== false) { |
|
127 | - fclose($this->sp); |
|
128 | - } |
|
129 | - $this->closed = true; |
|
130 | - } |
|
131 | - } |
|
124 | + public function close() { |
|
125 | + if($this->closed != true) { |
|
126 | + if(!$this->dry and $this->sp !== false) { |
|
127 | + fclose($this->sp); |
|
128 | + } |
|
129 | + $this->closed = true; |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - public function setDry($dry) { |
|
134 | - $this->dry = $dry; |
|
135 | - } |
|
133 | + public function setDry($dry) { |
|
134 | + $this->dry = $dry; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function getHostname() { |
|
141 | - return $this->getRemoteHost(); |
|
142 | - } |
|
137 | + /** |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function getHostname() { |
|
141 | + return $this->getRemoteHost(); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @return boolean |
|
146 | - */ |
|
147 | - public function getLocationInfo() { |
|
148 | - return $this->locationInfo; |
|
149 | - } |
|
144 | + /** |
|
145 | + * @return boolean |
|
146 | + */ |
|
147 | + public function getLocationInfo() { |
|
148 | + return $this->locationInfo; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return boolean |
|
153 | - */ |
|
154 | - public function getLog4jNamespace() { |
|
155 | - return $this->log4jNamespace; |
|
156 | - } |
|
151 | + /** |
|
152 | + * @return boolean |
|
153 | + */ |
|
154 | + public function getLog4jNamespace() { |
|
155 | + return $this->log4jNamespace; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @return integer |
|
160 | - */ |
|
161 | - public function getPort() { |
|
162 | - return $this->port; |
|
163 | - } |
|
158 | + /** |
|
159 | + * @return integer |
|
160 | + */ |
|
161 | + public function getPort() { |
|
162 | + return $this->port; |
|
163 | + } |
|
164 | 164 | |
165 | - public function getRemoteHost() { |
|
166 | - return $this->remoteHost; |
|
167 | - } |
|
165 | + public function getRemoteHost() { |
|
166 | + return $this->remoteHost; |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * @return integer |
|
171 | - */ |
|
172 | - public function getTimeout() { |
|
173 | - return $this->timeout; |
|
174 | - } |
|
169 | + /** |
|
170 | + * @return integer |
|
171 | + */ |
|
172 | + public function getTimeout() { |
|
173 | + return $this->timeout; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @var boolean |
|
178 | - */ |
|
179 | - public function getUseXml() { |
|
180 | - return $this->useXml; |
|
181 | - } |
|
176 | + /** |
|
177 | + * @var boolean |
|
178 | + */ |
|
179 | + public function getUseXml() { |
|
180 | + return $this->useXml; |
|
181 | + } |
|
182 | 182 | |
183 | - public function reset() { |
|
184 | - $this->close(); |
|
185 | - parent::reset(); |
|
186 | - } |
|
183 | + public function reset() { |
|
184 | + $this->close(); |
|
185 | + parent::reset(); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @param mixed |
|
190 | - */ |
|
191 | - public function setLocationInfo($flag) { |
|
192 | - $this->locationInfo = LoggerOptionConverter::toBoolean($flag, $this->getLocationInfo()); |
|
193 | - } |
|
188 | + /** |
|
189 | + * @param mixed |
|
190 | + */ |
|
191 | + public function setLocationInfo($flag) { |
|
192 | + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, $this->getLocationInfo()); |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @param mixed |
|
197 | - */ |
|
198 | - public function setLog4jNamespace($flag) { |
|
199 | - $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, $this->getLog4jNamespace()); |
|
200 | - } |
|
195 | + /** |
|
196 | + * @param mixed |
|
197 | + */ |
|
198 | + public function setLog4jNamespace($flag) { |
|
199 | + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, $this->getLog4jNamespace()); |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * @param integer |
|
204 | - */ |
|
205 | - public function setPort($port) { |
|
206 | - $port = LoggerOptionConverter::toInt($port, 0); |
|
207 | - if($port > 0 and $port < 65535) { |
|
208 | - $this->port = $port; |
|
209 | - } |
|
210 | - } |
|
202 | + /** |
|
203 | + * @param integer |
|
204 | + */ |
|
205 | + public function setPort($port) { |
|
206 | + $port = LoggerOptionConverter::toInt($port, 0); |
|
207 | + if($port > 0 and $port < 65535) { |
|
208 | + $this->port = $port; |
|
209 | + } |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * @param string |
|
214 | - */ |
|
215 | - public function setRemoteHost($hostname) { |
|
216 | - $this->remoteHost = $hostname; |
|
217 | - } |
|
212 | + /** |
|
213 | + * @param string |
|
214 | + */ |
|
215 | + public function setRemoteHost($hostname) { |
|
216 | + $this->remoteHost = $hostname; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @param integer |
|
221 | - */ |
|
222 | - public function setTimeout($timeout) { |
|
223 | - $this->timeout = LoggerOptionConverter::toInt($timeout, $this->getTimeout()); |
|
224 | - } |
|
219 | + /** |
|
220 | + * @param integer |
|
221 | + */ |
|
222 | + public function setTimeout($timeout) { |
|
223 | + $this->timeout = LoggerOptionConverter::toInt($timeout, $this->getTimeout()); |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * @param mixed |
|
228 | - */ |
|
229 | - public function setUseXml($flag) { |
|
230 | - $this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml()); |
|
231 | - } |
|
226 | + /** |
|
227 | + * @param mixed |
|
228 | + */ |
|
229 | + public function setUseXml($flag) { |
|
230 | + $this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml()); |
|
231 | + } |
|
232 | 232 | |
233 | - public function append(LoggerLoggingEvent $event) { |
|
234 | - if($this->sp || $this->dry) { |
|
235 | - if($this->getLocationInfo()) { |
|
236 | - $event->getLocationInformation(); |
|
237 | - } |
|
233 | + public function append(LoggerLoggingEvent $event) { |
|
234 | + if($this->sp || $this->dry) { |
|
235 | + if($this->getLocationInfo()) { |
|
236 | + $event->getLocationInformation(); |
|
237 | + } |
|
238 | 238 | |
239 | - if(!$this->getUseXml()) { |
|
240 | - $sEvent = serialize($event); |
|
241 | - if(!$this->dry) { |
|
242 | - fwrite($this->sp, $sEvent, strlen($sEvent)); |
|
243 | - } else { |
|
244 | - echo "DRY MODE OF SOCKET APPENDER: ".$sEvent; |
|
245 | - } |
|
246 | - } else { |
|
247 | - if(!$this->dry) { |
|
248 | - fwrite($this->sp, $this->xmlLayout->format($event)); |
|
249 | - } else { |
|
250 | - echo "DRY MODE OF SOCKET APPENDER: ".$this->xmlLayout->format($event); |
|
251 | - } |
|
252 | - } |
|
239 | + if(!$this->getUseXml()) { |
|
240 | + $sEvent = serialize($event); |
|
241 | + if(!$this->dry) { |
|
242 | + fwrite($this->sp, $sEvent, strlen($sEvent)); |
|
243 | + } else { |
|
244 | + echo "DRY MODE OF SOCKET APPENDER: ".$sEvent; |
|
245 | + } |
|
246 | + } else { |
|
247 | + if(!$this->dry) { |
|
248 | + fwrite($this->sp, $this->xmlLayout->format($event)); |
|
249 | + } else { |
|
250 | + echo "DRY MODE OF SOCKET APPENDER: ".$this->xmlLayout->format($event); |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | - // not sure about it... |
|
255 | - if(!$this->dry) { |
|
256 | - fflush($this->sp); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
254 | + // not sure about it... |
|
255 | + if(!$this->dry) { |
|
256 | + fflush($this->sp); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | } |
@@ -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 | * Implemented by classes capable of configuring log4php using a URL. |
@@ -26,28 +26,28 @@ discard block |
||
26 | 26 | */ |
27 | 27 | interface LoggerConfigurator { |
28 | 28 | |
29 | - /** |
|
30 | - * Special level value signifying inherited behaviour. The current |
|
31 | - * value of this string constant is <b>inherited</b>. |
|
32 | - * {@link CONFIGURATOR_NULL} is a synonym. |
|
33 | - */ |
|
34 | - const CONFIGURATOR_INHERITED = 'inherited'; |
|
29 | + /** |
|
30 | + * Special level value signifying inherited behaviour. The current |
|
31 | + * value of this string constant is <b>inherited</b>. |
|
32 | + * {@link CONFIGURATOR_NULL} is a synonym. |
|
33 | + */ |
|
34 | + const CONFIGURATOR_INHERITED = 'inherited'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Special level signifying inherited behaviour, same as |
|
38 | - * {@link CONFIGURATOR_INHERITED}. |
|
39 | - * The current value of this string constant is <b>null</b>. |
|
40 | - */ |
|
41 | - const CONFIGURATOR_NULL = 'null'; |
|
36 | + /** |
|
37 | + * Special level signifying inherited behaviour, same as |
|
38 | + * {@link CONFIGURATOR_INHERITED}. |
|
39 | + * The current value of this string constant is <b>null</b>. |
|
40 | + */ |
|
41 | + const CONFIGURATOR_NULL = 'null'; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Interpret a resource pointed by a <var>url</var> and configure accordingly. |
|
45 | - * |
|
46 | - * The configuration is done relative to the <var>repository</var> |
|
47 | - * parameter. |
|
48 | - * |
|
49 | - * @param string $url The URL to parse |
|
50 | - */ |
|
51 | - public function configure(LoggerHierarchy $hierarchy, $url = null); |
|
43 | + /** |
|
44 | + * Interpret a resource pointed by a <var>url</var> and configure accordingly. |
|
45 | + * |
|
46 | + * The configuration is done relative to the <var>repository</var> |
|
47 | + * parameter. |
|
48 | + * |
|
49 | + * @param string $url The URL to parse |
|
50 | + */ |
|
51 | + public function configure(LoggerHierarchy $hierarchy, $url = null); |
|
52 | 52 | |
53 | 53 | } |