@@ -26,28 +26,28 @@ |
||
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 | } |
@@ -39,13 +39,13 @@ |
||
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 | } |
@@ -63,401 +63,401 @@ |
||
63 | 63 | * @since 0.5 |
64 | 64 | */ |
65 | 65 | class LoggerConfiguratorIni implements LoggerConfigurator { |
66 | - const CATEGORY_PREFIX = "log4php.category."; |
|
67 | - const LOGGER_PREFIX = "log4php.logger."; |
|
68 | - const FACTORY_PREFIX = "log4php.factory"; |
|
69 | - const ADDITIVITY_PREFIX = "log4php.additivity."; |
|
70 | - const ROOT_CATEGORY_PREFIX = "log4php.rootCategory"; |
|
71 | - const ROOT_LOGGER_PREFIX = "log4php.rootLogger"; |
|
72 | - const APPENDER_PREFIX = "log4php.appender."; |
|
73 | - const RENDERER_PREFIX = "log4php.renderer."; |
|
74 | - const THRESHOLD_PREFIX = "log4php.threshold"; |
|
66 | + const CATEGORY_PREFIX = "log4php.category."; |
|
67 | + const LOGGER_PREFIX = "log4php.logger."; |
|
68 | + const FACTORY_PREFIX = "log4php.factory"; |
|
69 | + const ADDITIVITY_PREFIX = "log4php.additivity."; |
|
70 | + const ROOT_CATEGORY_PREFIX = "log4php.rootCategory"; |
|
71 | + const ROOT_LOGGER_PREFIX = "log4php.rootLogger"; |
|
72 | + const APPENDER_PREFIX = "log4php.appender."; |
|
73 | + const RENDERER_PREFIX = "log4php.renderer."; |
|
74 | + const THRESHOLD_PREFIX = "log4php.threshold"; |
|
75 | 75 | |
76 | - /** |
|
77 | - * Key for specifying the {@link LoggerFactory}. |
|
78 | - */ |
|
79 | - const LOGGER_FACTORY_KEY = "log4php.loggerFactory"; |
|
80 | - const LOGGER_DEBUG_KEY = "log4php.debug"; |
|
81 | - const INTERNAL_ROOT_NAME = "root"; |
|
76 | + /** |
|
77 | + * Key for specifying the {@link LoggerFactory}. |
|
78 | + */ |
|
79 | + const LOGGER_FACTORY_KEY = "log4php.loggerFactory"; |
|
80 | + const LOGGER_DEBUG_KEY = "log4php.debug"; |
|
81 | + const INTERNAL_ROOT_NAME = "root"; |
|
82 | 82 | |
83 | - /** |
|
84 | - * Constructor |
|
85 | - */ |
|
86 | - public function __construct() { |
|
87 | - } |
|
83 | + /** |
|
84 | + * Constructor |
|
85 | + */ |
|
86 | + public function __construct() { |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Read configuration from a file. |
|
91 | - * |
|
92 | - * <p>The function {@link PHP_MANUAL#parse_ini_file} is used to read the |
|
93 | - * file.</p> |
|
94 | - * |
|
95 | - * <b>The existing configuration is not cleared nor reset.</b> |
|
96 | - * If you require a different behavior, then call |
|
97 | - * {@link Logger::resetConfiguration()} |
|
98 | - * method before calling {@link doConfigure()}. |
|
99 | - * |
|
100 | - * <p>The configuration file consists of statements in the format |
|
101 | - * <b>key=value</b>. The syntax of different configuration |
|
102 | - * elements are discussed below. |
|
103 | - * |
|
104 | - * <p><b>Repository-wide threshold</b></p> |
|
105 | - * |
|
106 | - * <p>The repository-wide threshold filters logging requests by level |
|
107 | - * regardless of logger. The syntax is: |
|
108 | - * |
|
109 | - * <pre> |
|
110 | - * log4php.threshold=[level] |
|
111 | - * </pre> |
|
112 | - * |
|
113 | - * <p>The level value can consist of the string values OFF, FATAL, |
|
114 | - * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
115 | - * custom level value can be specified in the form |
|
116 | - * <samp>level#classname</samp>. By default the repository-wide threshold is set |
|
117 | - * to the lowest possible value, namely the level <b>ALL</b>. |
|
118 | - * </p> |
|
119 | - * |
|
120 | - * |
|
121 | - * <p><b>Appender configuration</b></p> |
|
122 | - * |
|
123 | - * <p>Appender configuration syntax is:</p> |
|
124 | - * <pre> |
|
125 | - * ; For appender named <i>appenderName</i>, set its class. |
|
126 | - * ; Note: The appender name can contain dots. |
|
127 | - * log4php.appender.appenderName=name_of_appender_class |
|
128 | - * |
|
129 | - * ; Set appender specific options. |
|
130 | - * |
|
131 | - * log4php.appender.appenderName.option1=value1 |
|
132 | - * log4php.appender.appenderName.optionN=valueN |
|
133 | - * </pre> |
|
134 | - * |
|
135 | - * For each named appender you can configure its {@link LoggerLayout}. The |
|
136 | - * syntax for configuring an appender's layout is: |
|
137 | - * <pre> |
|
138 | - * log4php.appender.appenderName.layout=name_of_layout_class |
|
139 | - * log4php.appender.appenderName.layout.option1=value1 |
|
140 | - * .... |
|
141 | - * log4php.appender.appenderName.layout.optionN=valueN |
|
142 | - * </pre> |
|
143 | - * |
|
144 | - * <p><b>Configuring loggers</b></p> |
|
145 | - * |
|
146 | - * <p>The syntax for configuring the root logger is: |
|
147 | - * <pre> |
|
148 | - * log4php.rootLogger=[level], appenderName, appenderName, ... |
|
149 | - * </pre> |
|
150 | - * |
|
151 | - * <p>This syntax means that an optional <i>level</i> can be |
|
152 | - * supplied followed by appender names separated by commas. |
|
153 | - * |
|
154 | - * <p>The level value can consist of the string values OFF, FATAL, |
|
155 | - * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
156 | - * custom level value can be specified in the form</p> |
|
157 | - * |
|
158 | - * <pre>level#classname</pre> |
|
159 | - * |
|
160 | - * <p>If a level value is specified, then the root level is set |
|
161 | - * to the corresponding level. If no level value is specified, |
|
162 | - * then the root level remains untouched. |
|
163 | - * |
|
164 | - * <p>The root logger can be assigned multiple appenders. |
|
165 | - * |
|
166 | - * <p>Each <i>appenderName</i> (separated by commas) will be added to |
|
167 | - * the root logger. The named appender is defined using the |
|
168 | - * appender syntax defined above. |
|
169 | - * |
|
170 | - * <p>For non-root categories the syntax is almost the same: |
|
171 | - * <pre> |
|
172 | - * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... |
|
173 | - * </pre> |
|
174 | - * |
|
175 | - * <p>The meaning of the optional level value is discussed above |
|
176 | - * in relation to the root logger. In addition however, the value |
|
177 | - * INHERITED can be specified meaning that the named logger should |
|
178 | - * inherit its level from the logger hierarchy.</p> |
|
179 | - * |
|
180 | - * <p>If no level value is supplied, then the level of the |
|
181 | - * named logger remains untouched.</p> |
|
182 | - * |
|
183 | - * <p>By default categories inherit their level from the |
|
184 | - * hierarchy. However, if you set the level of a logger and later |
|
185 | - * decide that that logger should inherit its level, then you should |
|
186 | - * specify INHERITED as the value for the level value. NULL is a |
|
187 | - * synonym for INHERITED.</p> |
|
188 | - * |
|
189 | - * <p>Similar to the root logger syntax, each <i>appenderName</i> |
|
190 | - * (separated by commas) will be attached to the named logger.</p> |
|
191 | - * |
|
192 | - * <p>See the <i>appender additivity rule</i> in the user manual for |
|
193 | - * the meaning of the <b>additivity</b> flag. |
|
194 | - * |
|
195 | - * <p><b>ObjectRenderers</b></p> |
|
196 | - * |
|
197 | - * <p>You can customize the way message objects of a given type are |
|
198 | - * converted to String before being logged. This is done by |
|
199 | - * specifying a {@link LoggerRendererObject} |
|
200 | - * for the object type would like to customize.</p> |
|
201 | - * |
|
202 | - * <p>The syntax is: |
|
203 | - * |
|
204 | - * <pre> |
|
205 | - * log4php.renderer.name_of_rendered_class=name_of_rendering.class |
|
206 | - * </pre> |
|
207 | - * |
|
208 | - * As in, |
|
209 | - * <pre> |
|
210 | - * log4php.renderer.myFruit=myFruitRenderer |
|
211 | - * </pre> |
|
212 | - * |
|
213 | - * <p><b>Logger Factories</b></p> |
|
214 | - * |
|
215 | - * The usage of custom logger factories is discouraged and no longer |
|
216 | - * documented. |
|
217 | - * |
|
218 | - * <p><b>Example</b></p> |
|
219 | - * |
|
220 | - * <p>An example configuration is given below. Other configuration |
|
221 | - * file examples are given in the <b>tests</b> folder. |
|
222 | - * |
|
223 | - * <pre> |
|
224 | - * ; Set options for appender named "A1". |
|
225 | - * ; Appender "A1" will be a LoggerAppenderSyslog |
|
226 | - * log4php.appender.A1=LoggerAppenderSyslog |
|
227 | - * |
|
228 | - * ; The syslog daemon resides on www.abc.net |
|
229 | - * log4php.appender.A1.ident=log4php-test |
|
230 | - * |
|
231 | - * ; A1's layout is a LoggerPatternLayout, using the conversion pattern |
|
232 | - * ; <b>%r %-5p %c{2} %M.%L %x - %m%n</b>. Thus, the log output will |
|
233 | - * ; include the relative time since the start of the application in |
|
234 | - * ; milliseconds, followed by the level of the log request, |
|
235 | - * ; followed by the two rightmost components of the logger name, |
|
236 | - * ; followed by the callers method name, followed by the line number, |
|
237 | - * ; the nested disgnostic context and finally the message itself. |
|
238 | - * ; Refer to the documentation of LoggerPatternLayout} for further information |
|
239 | - * ; on the syntax of the ConversionPattern key. |
|
240 | - * log4php.appender.A1.layout=LoggerPatternLayout |
|
241 | - * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n" |
|
242 | - * |
|
243 | - * ; Set options for appender named "A2" |
|
244 | - * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB |
|
245 | - * ; using at most one backup file. A2's layout is TTCC, using the |
|
246 | - * ; ISO8061 date format with context printing enabled. |
|
247 | - * log4php.appender.A2=LoggerAppenderRollingFile |
|
248 | - * log4php.appender.A2.MaxFileSize=10MB |
|
249 | - * log4php.appender.A2.MaxBackupIndex=1 |
|
250 | - * log4php.appender.A2.layout=LoggerLayoutTTCC |
|
251 | - * log4php.appender.A2.layout.ContextPrinting="true" |
|
252 | - * log4php.appender.A2.layout.DateFormat="%c" |
|
253 | - * |
|
254 | - * ; Root logger set to DEBUG using the A2 appender defined above. |
|
255 | - * log4php.rootLogger=DEBUG, A2 |
|
256 | - * |
|
257 | - * ; Logger definitions: |
|
258 | - * ; The SECURITY logger inherits is level from root. However, it's output |
|
259 | - * ; will go to A1 appender defined above. It's additivity is non-cumulative. |
|
260 | - * log4php.logger.SECURITY=INHERIT, A1 |
|
261 | - * log4php.additivity.SECURITY=false |
|
262 | - * |
|
263 | - * ; Only warnings or above will be logged for the logger "SECURITY.access". |
|
264 | - * ; Output will go to A1. |
|
265 | - * log4php.logger.SECURITY.access=WARN |
|
266 | - * |
|
267 | - * |
|
268 | - * ; The logger "class.of.the.day" inherits its level from the |
|
269 | - * ; logger hierarchy. Output will go to the appender's of the root |
|
270 | - * ; logger, A2 in this case. |
|
271 | - * log4php.logger.class.of.the.day=INHERIT |
|
272 | - * </pre> |
|
273 | - * |
|
274 | - * <p>Refer to the <b>setOption</b> method in each Appender and |
|
275 | - * Layout for class specific options.</p> |
|
276 | - * |
|
277 | - * <p>Use the <b>";"</b> character at the |
|
278 | - * beginning of a line for comments.</p> |
|
279 | - * |
|
280 | - * @param string $url The name of the configuration file where the |
|
281 | - * configuration information is stored. |
|
282 | - * @param LoggerHierarchy $repository the repository to apply the configuration |
|
283 | - */ |
|
284 | - public function configure(LoggerHierarchy $hierarchy, $url = '') { |
|
285 | - $properties = @parse_ini_file($url); |
|
286 | - if ($properties === false || count($properties) == 0) { |
|
287 | - $error = error_get_last(); |
|
288 | - throw new LoggerException("LoggerConfiguratorIni: ".$error['message']); |
|
289 | - } |
|
290 | - return $this->doConfigureProperties($properties, $hierarchy); |
|
291 | - } |
|
89 | + /** |
|
90 | + * Read configuration from a file. |
|
91 | + * |
|
92 | + * <p>The function {@link PHP_MANUAL#parse_ini_file} is used to read the |
|
93 | + * file.</p> |
|
94 | + * |
|
95 | + * <b>The existing configuration is not cleared nor reset.</b> |
|
96 | + * If you require a different behavior, then call |
|
97 | + * {@link Logger::resetConfiguration()} |
|
98 | + * method before calling {@link doConfigure()}. |
|
99 | + * |
|
100 | + * <p>The configuration file consists of statements in the format |
|
101 | + * <b>key=value</b>. The syntax of different configuration |
|
102 | + * elements are discussed below. |
|
103 | + * |
|
104 | + * <p><b>Repository-wide threshold</b></p> |
|
105 | + * |
|
106 | + * <p>The repository-wide threshold filters logging requests by level |
|
107 | + * regardless of logger. The syntax is: |
|
108 | + * |
|
109 | + * <pre> |
|
110 | + * log4php.threshold=[level] |
|
111 | + * </pre> |
|
112 | + * |
|
113 | + * <p>The level value can consist of the string values OFF, FATAL, |
|
114 | + * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
115 | + * custom level value can be specified in the form |
|
116 | + * <samp>level#classname</samp>. By default the repository-wide threshold is set |
|
117 | + * to the lowest possible value, namely the level <b>ALL</b>. |
|
118 | + * </p> |
|
119 | + * |
|
120 | + * |
|
121 | + * <p><b>Appender configuration</b></p> |
|
122 | + * |
|
123 | + * <p>Appender configuration syntax is:</p> |
|
124 | + * <pre> |
|
125 | + * ; For appender named <i>appenderName</i>, set its class. |
|
126 | + * ; Note: The appender name can contain dots. |
|
127 | + * log4php.appender.appenderName=name_of_appender_class |
|
128 | + * |
|
129 | + * ; Set appender specific options. |
|
130 | + * |
|
131 | + * log4php.appender.appenderName.option1=value1 |
|
132 | + * log4php.appender.appenderName.optionN=valueN |
|
133 | + * </pre> |
|
134 | + * |
|
135 | + * For each named appender you can configure its {@link LoggerLayout}. The |
|
136 | + * syntax for configuring an appender's layout is: |
|
137 | + * <pre> |
|
138 | + * log4php.appender.appenderName.layout=name_of_layout_class |
|
139 | + * log4php.appender.appenderName.layout.option1=value1 |
|
140 | + * .... |
|
141 | + * log4php.appender.appenderName.layout.optionN=valueN |
|
142 | + * </pre> |
|
143 | + * |
|
144 | + * <p><b>Configuring loggers</b></p> |
|
145 | + * |
|
146 | + * <p>The syntax for configuring the root logger is: |
|
147 | + * <pre> |
|
148 | + * log4php.rootLogger=[level], appenderName, appenderName, ... |
|
149 | + * </pre> |
|
150 | + * |
|
151 | + * <p>This syntax means that an optional <i>level</i> can be |
|
152 | + * supplied followed by appender names separated by commas. |
|
153 | + * |
|
154 | + * <p>The level value can consist of the string values OFF, FATAL, |
|
155 | + * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
156 | + * custom level value can be specified in the form</p> |
|
157 | + * |
|
158 | + * <pre>level#classname</pre> |
|
159 | + * |
|
160 | + * <p>If a level value is specified, then the root level is set |
|
161 | + * to the corresponding level. If no level value is specified, |
|
162 | + * then the root level remains untouched. |
|
163 | + * |
|
164 | + * <p>The root logger can be assigned multiple appenders. |
|
165 | + * |
|
166 | + * <p>Each <i>appenderName</i> (separated by commas) will be added to |
|
167 | + * the root logger. The named appender is defined using the |
|
168 | + * appender syntax defined above. |
|
169 | + * |
|
170 | + * <p>For non-root categories the syntax is almost the same: |
|
171 | + * <pre> |
|
172 | + * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... |
|
173 | + * </pre> |
|
174 | + * |
|
175 | + * <p>The meaning of the optional level value is discussed above |
|
176 | + * in relation to the root logger. In addition however, the value |
|
177 | + * INHERITED can be specified meaning that the named logger should |
|
178 | + * inherit its level from the logger hierarchy.</p> |
|
179 | + * |
|
180 | + * <p>If no level value is supplied, then the level of the |
|
181 | + * named logger remains untouched.</p> |
|
182 | + * |
|
183 | + * <p>By default categories inherit their level from the |
|
184 | + * hierarchy. However, if you set the level of a logger and later |
|
185 | + * decide that that logger should inherit its level, then you should |
|
186 | + * specify INHERITED as the value for the level value. NULL is a |
|
187 | + * synonym for INHERITED.</p> |
|
188 | + * |
|
189 | + * <p>Similar to the root logger syntax, each <i>appenderName</i> |
|
190 | + * (separated by commas) will be attached to the named logger.</p> |
|
191 | + * |
|
192 | + * <p>See the <i>appender additivity rule</i> in the user manual for |
|
193 | + * the meaning of the <b>additivity</b> flag. |
|
194 | + * |
|
195 | + * <p><b>ObjectRenderers</b></p> |
|
196 | + * |
|
197 | + * <p>You can customize the way message objects of a given type are |
|
198 | + * converted to String before being logged. This is done by |
|
199 | + * specifying a {@link LoggerRendererObject} |
|
200 | + * for the object type would like to customize.</p> |
|
201 | + * |
|
202 | + * <p>The syntax is: |
|
203 | + * |
|
204 | + * <pre> |
|
205 | + * log4php.renderer.name_of_rendered_class=name_of_rendering.class |
|
206 | + * </pre> |
|
207 | + * |
|
208 | + * As in, |
|
209 | + * <pre> |
|
210 | + * log4php.renderer.myFruit=myFruitRenderer |
|
211 | + * </pre> |
|
212 | + * |
|
213 | + * <p><b>Logger Factories</b></p> |
|
214 | + * |
|
215 | + * The usage of custom logger factories is discouraged and no longer |
|
216 | + * documented. |
|
217 | + * |
|
218 | + * <p><b>Example</b></p> |
|
219 | + * |
|
220 | + * <p>An example configuration is given below. Other configuration |
|
221 | + * file examples are given in the <b>tests</b> folder. |
|
222 | + * |
|
223 | + * <pre> |
|
224 | + * ; Set options for appender named "A1". |
|
225 | + * ; Appender "A1" will be a LoggerAppenderSyslog |
|
226 | + * log4php.appender.A1=LoggerAppenderSyslog |
|
227 | + * |
|
228 | + * ; The syslog daemon resides on www.abc.net |
|
229 | + * log4php.appender.A1.ident=log4php-test |
|
230 | + * |
|
231 | + * ; A1's layout is a LoggerPatternLayout, using the conversion pattern |
|
232 | + * ; <b>%r %-5p %c{2} %M.%L %x - %m%n</b>. Thus, the log output will |
|
233 | + * ; include the relative time since the start of the application in |
|
234 | + * ; milliseconds, followed by the level of the log request, |
|
235 | + * ; followed by the two rightmost components of the logger name, |
|
236 | + * ; followed by the callers method name, followed by the line number, |
|
237 | + * ; the nested disgnostic context and finally the message itself. |
|
238 | + * ; Refer to the documentation of LoggerPatternLayout} for further information |
|
239 | + * ; on the syntax of the ConversionPattern key. |
|
240 | + * log4php.appender.A1.layout=LoggerPatternLayout |
|
241 | + * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n" |
|
242 | + * |
|
243 | + * ; Set options for appender named "A2" |
|
244 | + * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB |
|
245 | + * ; using at most one backup file. A2's layout is TTCC, using the |
|
246 | + * ; ISO8061 date format with context printing enabled. |
|
247 | + * log4php.appender.A2=LoggerAppenderRollingFile |
|
248 | + * log4php.appender.A2.MaxFileSize=10MB |
|
249 | + * log4php.appender.A2.MaxBackupIndex=1 |
|
250 | + * log4php.appender.A2.layout=LoggerLayoutTTCC |
|
251 | + * log4php.appender.A2.layout.ContextPrinting="true" |
|
252 | + * log4php.appender.A2.layout.DateFormat="%c" |
|
253 | + * |
|
254 | + * ; Root logger set to DEBUG using the A2 appender defined above. |
|
255 | + * log4php.rootLogger=DEBUG, A2 |
|
256 | + * |
|
257 | + * ; Logger definitions: |
|
258 | + * ; The SECURITY logger inherits is level from root. However, it's output |
|
259 | + * ; will go to A1 appender defined above. It's additivity is non-cumulative. |
|
260 | + * log4php.logger.SECURITY=INHERIT, A1 |
|
261 | + * log4php.additivity.SECURITY=false |
|
262 | + * |
|
263 | + * ; Only warnings or above will be logged for the logger "SECURITY.access". |
|
264 | + * ; Output will go to A1. |
|
265 | + * log4php.logger.SECURITY.access=WARN |
|
266 | + * |
|
267 | + * |
|
268 | + * ; The logger "class.of.the.day" inherits its level from the |
|
269 | + * ; logger hierarchy. Output will go to the appender's of the root |
|
270 | + * ; logger, A2 in this case. |
|
271 | + * log4php.logger.class.of.the.day=INHERIT |
|
272 | + * </pre> |
|
273 | + * |
|
274 | + * <p>Refer to the <b>setOption</b> method in each Appender and |
|
275 | + * Layout for class specific options.</p> |
|
276 | + * |
|
277 | + * <p>Use the <b>";"</b> character at the |
|
278 | + * beginning of a line for comments.</p> |
|
279 | + * |
|
280 | + * @param string $url The name of the configuration file where the |
|
281 | + * configuration information is stored. |
|
282 | + * @param LoggerHierarchy $repository the repository to apply the configuration |
|
283 | + */ |
|
284 | + public function configure(LoggerHierarchy $hierarchy, $url = '') { |
|
285 | + $properties = @parse_ini_file($url); |
|
286 | + if ($properties === false || count($properties) == 0) { |
|
287 | + $error = error_get_last(); |
|
288 | + throw new LoggerException("LoggerConfiguratorIni: ".$error['message']); |
|
289 | + } |
|
290 | + return $this->doConfigureProperties($properties, $hierarchy); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * Read configuration options from <b>properties</b>. |
|
295 | - * |
|
296 | - * @see doConfigure(). |
|
297 | - * @param array $properties |
|
298 | - * @param LoggerHierarchy $hierarchy |
|
299 | - */ |
|
300 | - private function doConfigureProperties($properties, LoggerHierarchy $hierarchy) { |
|
301 | - $thresholdStr = @$properties[self::THRESHOLD_PREFIX]; |
|
302 | - $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll())); |
|
303 | - $this->configureRootCategory($properties, $hierarchy); |
|
304 | - $this->parseCatsAndRenderers($properties, $hierarchy); |
|
305 | - return true; |
|
306 | - } |
|
293 | + /** |
|
294 | + * Read configuration options from <b>properties</b>. |
|
295 | + * |
|
296 | + * @see doConfigure(). |
|
297 | + * @param array $properties |
|
298 | + * @param LoggerHierarchy $hierarchy |
|
299 | + */ |
|
300 | + private function doConfigureProperties($properties, LoggerHierarchy $hierarchy) { |
|
301 | + $thresholdStr = @$properties[self::THRESHOLD_PREFIX]; |
|
302 | + $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll())); |
|
303 | + $this->configureRootCategory($properties, $hierarchy); |
|
304 | + $this->parseCatsAndRenderers($properties, $hierarchy); |
|
305 | + return true; |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * @param array $props array of properties |
|
310 | - * @param LoggerHierarchy $hierarchy |
|
311 | - */ |
|
312 | - private function configureRootCategory($props, LoggerHierarchy $hierarchy) { |
|
313 | - $effectivePrefix = self::ROOT_LOGGER_PREFIX; |
|
314 | - $value = @$props[self::ROOT_LOGGER_PREFIX]; |
|
308 | + /** |
|
309 | + * @param array $props array of properties |
|
310 | + * @param LoggerHierarchy $hierarchy |
|
311 | + */ |
|
312 | + private function configureRootCategory($props, LoggerHierarchy $hierarchy) { |
|
313 | + $effectivePrefix = self::ROOT_LOGGER_PREFIX; |
|
314 | + $value = @$props[self::ROOT_LOGGER_PREFIX]; |
|
315 | 315 | |
316 | - if(empty($value)) { |
|
317 | - $value = @$props[self::ROOT_CATEGORY_PREFIX]; |
|
318 | - $effectivePrefix = self::ROOT_CATEGORY_PREFIX; |
|
319 | - } |
|
316 | + if(empty($value)) { |
|
317 | + $value = @$props[self::ROOT_CATEGORY_PREFIX]; |
|
318 | + $effectivePrefix = self::ROOT_CATEGORY_PREFIX; |
|
319 | + } |
|
320 | 320 | |
321 | - if(empty($value)) { |
|
322 | - // TODO "Could not find root logger information. Is this OK?" |
|
323 | - } else { |
|
324 | - $root = $hierarchy->getRootLogger(); |
|
325 | - $this->parseCategory($props, $root, $effectivePrefix, self::INTERNAL_ROOT_NAME, $value); |
|
326 | - } |
|
327 | - } |
|
321 | + if(empty($value)) { |
|
322 | + // TODO "Could not find root logger information. Is this OK?" |
|
323 | + } else { |
|
324 | + $root = $hierarchy->getRootLogger(); |
|
325 | + $this->parseCategory($props, $root, $effectivePrefix, self::INTERNAL_ROOT_NAME, $value); |
|
326 | + } |
|
327 | + } |
|
328 | 328 | |
329 | - /** |
|
330 | - * Parse non-root elements, such non-root categories and renderers. |
|
331 | - * |
|
332 | - * @param array $props array of properties |
|
333 | - * @param LoggerHierarchy $hierarchy |
|
334 | - */ |
|
335 | - private function parseCatsAndRenderers($props, LoggerHierarchy $hierarchy) { |
|
336 | - while(list($key,$value) = each($props)) { |
|
337 | - if(strpos($key, self::CATEGORY_PREFIX) === 0 or |
|
338 | - strpos($key, self::LOGGER_PREFIX) === 0) { |
|
339 | - if(strpos($key, self::CATEGORY_PREFIX) === 0) { |
|
340 | - $loggerName = substr($key, strlen(self::CATEGORY_PREFIX)); |
|
341 | - } else if(strpos($key, self::LOGGER_PREFIX) === 0) { |
|
342 | - $loggerName = substr($key, strlen(self::LOGGER_PREFIX)); |
|
343 | - } |
|
329 | + /** |
|
330 | + * Parse non-root elements, such non-root categories and renderers. |
|
331 | + * |
|
332 | + * @param array $props array of properties |
|
333 | + * @param LoggerHierarchy $hierarchy |
|
334 | + */ |
|
335 | + private function parseCatsAndRenderers($props, LoggerHierarchy $hierarchy) { |
|
336 | + while(list($key,$value) = each($props)) { |
|
337 | + if(strpos($key, self::CATEGORY_PREFIX) === 0 or |
|
338 | + strpos($key, self::LOGGER_PREFIX) === 0) { |
|
339 | + if(strpos($key, self::CATEGORY_PREFIX) === 0) { |
|
340 | + $loggerName = substr($key, strlen(self::CATEGORY_PREFIX)); |
|
341 | + } else if(strpos($key, self::LOGGER_PREFIX) === 0) { |
|
342 | + $loggerName = substr($key, strlen(self::LOGGER_PREFIX)); |
|
343 | + } |
|
344 | 344 | |
345 | - $logger = $hierarchy->getLogger($loggerName); |
|
346 | - $this->parseCategory($props, $logger, $key, $loggerName, $value); |
|
347 | - $this->parseAdditivityForLogger($props, $logger, $loggerName); |
|
348 | - } else if(strpos($key, self::RENDERER_PREFIX) === 0) { |
|
349 | - $renderedClass = substr($key, strlen(self::RENDERER_PREFIX)); |
|
350 | - $renderingClass = $value; |
|
351 | - $hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
345 | + $logger = $hierarchy->getLogger($loggerName); |
|
346 | + $this->parseCategory($props, $logger, $key, $loggerName, $value); |
|
347 | + $this->parseAdditivityForLogger($props, $logger, $loggerName); |
|
348 | + } else if(strpos($key, self::RENDERER_PREFIX) === 0) { |
|
349 | + $renderedClass = substr($key, strlen(self::RENDERER_PREFIX)); |
|
350 | + $renderingClass = $value; |
|
351 | + $hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | 355 | |
356 | - /** |
|
357 | - * Parse the additivity option for a non-root category. |
|
358 | - * |
|
359 | - * @param array $props array of properties |
|
360 | - * @param Logger $cat |
|
361 | - * @param string $loggerName |
|
362 | - */ |
|
363 | - private function parseAdditivityForLogger($props, Logger $cat, $loggerName) { |
|
364 | - $value = LoggerOptionConverter::findAndSubst(self::ADDITIVITY_PREFIX . $loggerName, $props); |
|
356 | + /** |
|
357 | + * Parse the additivity option for a non-root category. |
|
358 | + * |
|
359 | + * @param array $props array of properties |
|
360 | + * @param Logger $cat |
|
361 | + * @param string $loggerName |
|
362 | + */ |
|
363 | + private function parseAdditivityForLogger($props, Logger $cat, $loggerName) { |
|
364 | + $value = LoggerOptionConverter::findAndSubst(self::ADDITIVITY_PREFIX . $loggerName, $props); |
|
365 | 365 | |
366 | - // touch additivity only if necessary |
|
367 | - if(!empty($value)) { |
|
368 | - $additivity = LoggerOptionConverter::toBoolean($value, true); |
|
369 | - $cat->setAdditivity($additivity); |
|
370 | - } |
|
371 | - } |
|
366 | + // touch additivity only if necessary |
|
367 | + if(!empty($value)) { |
|
368 | + $additivity = LoggerOptionConverter::toBoolean($value, true); |
|
369 | + $cat->setAdditivity($additivity); |
|
370 | + } |
|
371 | + } |
|
372 | 372 | |
373 | - /** |
|
374 | - * This method must work for the root category as well. |
|
375 | - * |
|
376 | - * @param array $props array of properties |
|
377 | - * @param Logger $logger |
|
378 | - * @param string $optionKey |
|
379 | - * @param string $loggerName |
|
380 | - * @param string $value |
|
381 | - * @return Logger |
|
382 | - */ |
|
383 | - private function parseCategory($props, Logger $logger, $optionKey, $loggerName, $value) { |
|
384 | - // We must skip over ',' but not white space |
|
385 | - $st = explode(',', $value); |
|
373 | + /** |
|
374 | + * This method must work for the root category as well. |
|
375 | + * |
|
376 | + * @param array $props array of properties |
|
377 | + * @param Logger $logger |
|
378 | + * @param string $optionKey |
|
379 | + * @param string $loggerName |
|
380 | + * @param string $value |
|
381 | + * @return Logger |
|
382 | + */ |
|
383 | + private function parseCategory($props, Logger $logger, $optionKey, $loggerName, $value) { |
|
384 | + // We must skip over ',' but not white space |
|
385 | + $st = explode(',', $value); |
|
386 | 386 | |
387 | - // If value is not in the form ", appender.." or "", then we should set |
|
388 | - // the level of the loggeregory. |
|
387 | + // If value is not in the form ", appender.." or "", then we should set |
|
388 | + // the level of the loggeregory. |
|
389 | 389 | |
390 | - if(!(empty($value) || @$value[0] == ',')) { |
|
391 | - // just to be on the safe side... |
|
392 | - if(count($st) == 0) { |
|
393 | - return; |
|
394 | - } |
|
395 | - $levelStr = current($st); |
|
390 | + if(!(empty($value) || @$value[0] == ',')) { |
|
391 | + // just to be on the safe side... |
|
392 | + if(count($st) == 0) { |
|
393 | + return; |
|
394 | + } |
|
395 | + $levelStr = current($st); |
|
396 | 396 | |
397 | - // If the level value is inherited, set category level value to |
|
398 | - // null. We also check that the user has not specified inherited for the |
|
399 | - // root category. |
|
400 | - if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { |
|
401 | - if($loggerName == self::INTERNAL_ROOT_NAME) { |
|
402 | - // TODO: throw exception? "The root logger cannot be set to null." |
|
403 | - } else { |
|
404 | - $logger->setLevel(null); |
|
405 | - } |
|
406 | - } else { |
|
407 | - $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug())); |
|
408 | - } |
|
409 | - } |
|
397 | + // If the level value is inherited, set category level value to |
|
398 | + // null. We also check that the user has not specified inherited for the |
|
399 | + // root category. |
|
400 | + if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { |
|
401 | + if($loggerName == self::INTERNAL_ROOT_NAME) { |
|
402 | + // TODO: throw exception? "The root logger cannot be set to null." |
|
403 | + } else { |
|
404 | + $logger->setLevel(null); |
|
405 | + } |
|
406 | + } else { |
|
407 | + $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug())); |
|
408 | + } |
|
409 | + } |
|
410 | 410 | |
411 | - // TODO: removing should be done by the logger, if necessary and wanted |
|
412 | - // $logger->removeAllAppenders(); |
|
413 | - while($appenderName = next($st)) { |
|
414 | - $appenderName = trim($appenderName); |
|
415 | - if(empty($appenderName)) { |
|
416 | - continue; |
|
417 | - } |
|
411 | + // TODO: removing should be done by the logger, if necessary and wanted |
|
412 | + // $logger->removeAllAppenders(); |
|
413 | + while($appenderName = next($st)) { |
|
414 | + $appenderName = trim($appenderName); |
|
415 | + if(empty($appenderName)) { |
|
416 | + continue; |
|
417 | + } |
|
418 | 418 | |
419 | - $appender = $this->parseAppender($props, $appenderName); |
|
420 | - if($appender !== null) { |
|
421 | - $logger->addAppender($appender); |
|
422 | - } |
|
423 | - } |
|
424 | - } |
|
419 | + $appender = $this->parseAppender($props, $appenderName); |
|
420 | + if($appender !== null) { |
|
421 | + $logger->addAppender($appender); |
|
422 | + } |
|
423 | + } |
|
424 | + } |
|
425 | 425 | |
426 | - /** |
|
427 | - * @param array $props array of properties |
|
428 | - * @param string $appenderName |
|
429 | - * @return LoggerAppender |
|
430 | - */ |
|
431 | - private function parseAppender($props, $appenderName) { |
|
432 | - $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
433 | - $prefix = self::APPENDER_PREFIX . $appenderName; |
|
434 | - if($appender === null) { |
|
435 | - // Appender was not previously initialized. |
|
436 | - $appenderClass = @$props[$prefix]; |
|
437 | - $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderClass); |
|
438 | - if($appender === null) { |
|
439 | - return null; |
|
440 | - } |
|
441 | - } |
|
426 | + /** |
|
427 | + * @param array $props array of properties |
|
428 | + * @param string $appenderName |
|
429 | + * @return LoggerAppender |
|
430 | + */ |
|
431 | + private function parseAppender($props, $appenderName) { |
|
432 | + $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
433 | + $prefix = self::APPENDER_PREFIX . $appenderName; |
|
434 | + if($appender === null) { |
|
435 | + // Appender was not previously initialized. |
|
436 | + $appenderClass = @$props[$prefix]; |
|
437 | + $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderClass); |
|
438 | + if($appender === null) { |
|
439 | + return null; |
|
440 | + } |
|
441 | + } |
|
442 | 442 | |
443 | - if($appender->requiresLayout() ) { |
|
444 | - $layoutPrefix = $prefix . ".layout"; |
|
445 | - $layoutClass = @$props[$layoutPrefix]; |
|
446 | - $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); |
|
447 | - if(empty($layoutClass)) { |
|
448 | - $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
449 | - } else { |
|
450 | - $layout = LoggerReflectionUtils::createObject($layoutClass); |
|
451 | - if($layout === null) { |
|
452 | - $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
453 | - } |
|
454 | - } |
|
443 | + if($appender->requiresLayout() ) { |
|
444 | + $layoutPrefix = $prefix . ".layout"; |
|
445 | + $layoutClass = @$props[$layoutPrefix]; |
|
446 | + $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); |
|
447 | + if(empty($layoutClass)) { |
|
448 | + $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
449 | + } else { |
|
450 | + $layout = LoggerReflectionUtils::createObject($layoutClass); |
|
451 | + if($layout === null) { |
|
452 | + $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
453 | + } |
|
454 | + } |
|
455 | 455 | |
456 | - LoggerReflectionUtils::setPropertiesByObject($layout, $props, $layoutPrefix . "."); |
|
457 | - $appender->setLayout($layout); |
|
456 | + LoggerReflectionUtils::setPropertiesByObject($layout, $props, $layoutPrefix . "."); |
|
457 | + $appender->setLayout($layout); |
|
458 | 458 | |
459 | - } |
|
460 | - LoggerReflectionUtils::setPropertiesByObject($appender, $props, $prefix . "."); |
|
461 | - return $appender; |
|
462 | - } |
|
459 | + } |
|
460 | + LoggerReflectionUtils::setPropertiesByObject($appender, $props, $prefix . "."); |
|
461 | + return $appender; |
|
462 | + } |
|
463 | 463 | } |
@@ -55,62 +55,62 @@ |
||
55 | 55 | * @package log4php |
56 | 56 | */ |
57 | 57 | class LoggerMDC { |
58 | - /** |
|
59 | - * Put a context value as identified with the key parameter into the current thread's |
|
60 | - * context map. |
|
61 | - * |
|
62 | - * <p>If the current thread does not have a context map it is |
|
63 | - * created as a side effect.</p> |
|
64 | - * |
|
65 | - * <p>Note that you cannot put more than {@link self::HT_SIZE} keys.</p> |
|
66 | - * |
|
67 | - * @param string $key the key |
|
68 | - * @param string $value the value |
|
69 | - * @static |
|
70 | - */ |
|
71 | - public static function put($key, $value) { |
|
72 | - $GLOBALS['log4php.LoggerMDC.ht'][$key] = $value; |
|
73 | - } |
|
58 | + /** |
|
59 | + * Put a context value as identified with the key parameter into the current thread's |
|
60 | + * context map. |
|
61 | + * |
|
62 | + * <p>If the current thread does not have a context map it is |
|
63 | + * created as a side effect.</p> |
|
64 | + * |
|
65 | + * <p>Note that you cannot put more than {@link self::HT_SIZE} keys.</p> |
|
66 | + * |
|
67 | + * @param string $key the key |
|
68 | + * @param string $value the value |
|
69 | + * @static |
|
70 | + */ |
|
71 | + public static function put($key, $value) { |
|
72 | + $GLOBALS['log4php.LoggerMDC.ht'][$key] = $value; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get the context identified by the key parameter. |
|
77 | - * |
|
78 | - * <p>You can use special key identifiers to map values in |
|
79 | - * PHP $_SERVER and $_ENV vars. Just put a 'server.' or 'env.' |
|
80 | - * followed by the var name you want to refer.</p> |
|
81 | - * |
|
82 | - * <p>This method has no side effects.</p> |
|
83 | - * |
|
84 | - * @param string $key |
|
85 | - * @return string |
|
86 | - * @static |
|
87 | - */ |
|
88 | - public static function get($key) { |
|
89 | - if(!empty($key)) { |
|
90 | - if(strpos($key, 'server.') === 0) { |
|
91 | - $varName = substr($key, 7); |
|
92 | - return @$_SERVER[$varName]; |
|
93 | - } else if(strpos($key, 'env.') === 0) { |
|
94 | - $varName = substr($key, 4); |
|
95 | - return @$_ENV[$varName]; |
|
96 | - } else if (isset($GLOBALS['log4php.LoggerMDC.ht'][$key])) { |
|
97 | - return $GLOBALS['log4php.LoggerMDC.ht'][$key]; |
|
98 | - } |
|
99 | - } |
|
100 | - return ''; |
|
101 | - } |
|
75 | + /** |
|
76 | + * Get the context identified by the key parameter. |
|
77 | + * |
|
78 | + * <p>You can use special key identifiers to map values in |
|
79 | + * PHP $_SERVER and $_ENV vars. Just put a 'server.' or 'env.' |
|
80 | + * followed by the var name you want to refer.</p> |
|
81 | + * |
|
82 | + * <p>This method has no side effects.</p> |
|
83 | + * |
|
84 | + * @param string $key |
|
85 | + * @return string |
|
86 | + * @static |
|
87 | + */ |
|
88 | + public static function get($key) { |
|
89 | + if(!empty($key)) { |
|
90 | + if(strpos($key, 'server.') === 0) { |
|
91 | + $varName = substr($key, 7); |
|
92 | + return @$_SERVER[$varName]; |
|
93 | + } else if(strpos($key, 'env.') === 0) { |
|
94 | + $varName = substr($key, 4); |
|
95 | + return @$_ENV[$varName]; |
|
96 | + } else if (isset($GLOBALS['log4php.LoggerMDC.ht'][$key])) { |
|
97 | + return $GLOBALS['log4php.LoggerMDC.ht'][$key]; |
|
98 | + } |
|
99 | + } |
|
100 | + return ''; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Remove the the context identified by the key parameter. |
|
105 | - * |
|
106 | - * It only affects user mappings. |
|
107 | - * |
|
108 | - * @param string $key |
|
109 | - * @return string |
|
110 | - * @static |
|
111 | - */ |
|
112 | - public static function remove($key) { |
|
113 | - unset($GLOBALS['log4php.LoggerMDC.ht'][$key]); |
|
114 | - } |
|
103 | + /** |
|
104 | + * Remove the the context identified by the key parameter. |
|
105 | + * |
|
106 | + * It only affects user mappings. |
|
107 | + * |
|
108 | + * @param string $key |
|
109 | + * @return string |
|
110 | + * @static |
|
111 | + */ |
|
112 | + public static function remove($key) { |
|
113 | + unset($GLOBALS['log4php.LoggerMDC.ht'][$key]); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -26,45 +26,45 @@ |
||
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 | } |
@@ -47,58 +47,58 @@ |
||
47 | 47 | */ |
48 | 48 | class LoggerFilterLevelMatch extends LoggerFilter { |
49 | 49 | |
50 | - /** |
|
51 | - * Indicates if this event should be accepted or denied on match |
|
52 | - * @var boolean |
|
53 | - */ |
|
54 | - private $acceptOnMatch = true; |
|
50 | + /** |
|
51 | + * Indicates if this event should be accepted or denied on match |
|
52 | + * @var boolean |
|
53 | + */ |
|
54 | + private $acceptOnMatch = true; |
|
55 | 55 | |
56 | - /** |
|
57 | - * The level, when to match |
|
58 | - * @var LoggerLevel |
|
59 | - */ |
|
60 | - private $levelToMatch; |
|
56 | + /** |
|
57 | + * The level, when to match |
|
58 | + * @var LoggerLevel |
|
59 | + */ |
|
60 | + private $levelToMatch; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param boolean $acceptOnMatch |
|
64 | - */ |
|
65 | - public function setAcceptOnMatch($acceptOnMatch) { |
|
66 | - $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true); |
|
67 | - } |
|
62 | + /** |
|
63 | + * @param boolean $acceptOnMatch |
|
64 | + */ |
|
65 | + public function setAcceptOnMatch($acceptOnMatch) { |
|
66 | + $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string $l the level to match |
|
71 | - */ |
|
72 | - public function setLevelToMatch($l) { |
|
73 | - if($l instanceof LoggerLevel) { |
|
74 | - $this->levelToMatch = $l; |
|
75 | - } else { |
|
76 | - $this->levelToMatch = LoggerOptionConverter::toLevel($l, null); |
|
77 | - } |
|
78 | - } |
|
69 | + /** |
|
70 | + * @param string $l the level to match |
|
71 | + */ |
|
72 | + public function setLevelToMatch($l) { |
|
73 | + if($l instanceof LoggerLevel) { |
|
74 | + $this->levelToMatch = $l; |
|
75 | + } else { |
|
76 | + $this->levelToMatch = LoggerOptionConverter::toLevel($l, null); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Return the decision of this filter. |
|
82 | - * |
|
83 | - * Returns {@link LoggerFilter::NEUTRAL} if the <b><var>LevelToMatch</var></b> |
|
84 | - * option is not set or if there is not match. Otherwise, if there is a |
|
85 | - * match, then the returned decision is {@link LoggerFilter::ACCEPT} if the |
|
86 | - * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The |
|
87 | - * returned decision is {@link LoggerFilter::DENY} if the |
|
88 | - * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>. |
|
89 | - * |
|
90 | - * @param LoggerLoggingEvent $event |
|
91 | - * @return integer |
|
92 | - */ |
|
93 | - public function decide(LoggerLoggingEvent $event) { |
|
94 | - if($this->levelToMatch === null) { |
|
95 | - return LoggerFilter::NEUTRAL; |
|
96 | - } |
|
80 | + /** |
|
81 | + * Return the decision of this filter. |
|
82 | + * |
|
83 | + * Returns {@link LoggerFilter::NEUTRAL} if the <b><var>LevelToMatch</var></b> |
|
84 | + * option is not set or if there is not match. Otherwise, if there is a |
|
85 | + * match, then the returned decision is {@link LoggerFilter::ACCEPT} if the |
|
86 | + * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The |
|
87 | + * returned decision is {@link LoggerFilter::DENY} if the |
|
88 | + * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>. |
|
89 | + * |
|
90 | + * @param LoggerLoggingEvent $event |
|
91 | + * @return integer |
|
92 | + */ |
|
93 | + public function decide(LoggerLoggingEvent $event) { |
|
94 | + if($this->levelToMatch === null) { |
|
95 | + return LoggerFilter::NEUTRAL; |
|
96 | + } |
|
97 | 97 | |
98 | - if($this->levelToMatch->equals($event->getLevel())) { |
|
99 | - return $this->acceptOnMatch ? LoggerFilter::ACCEPT : LoggerFilter::DENY; |
|
100 | - } else { |
|
101 | - return LoggerFilter::NEUTRAL; |
|
102 | - } |
|
103 | - } |
|
98 | + if($this->levelToMatch->equals($event->getLevel())) { |
|
99 | + return $this->acceptOnMatch ? LoggerFilter::ACCEPT : LoggerFilter::DENY; |
|
100 | + } else { |
|
101 | + return LoggerFilter::NEUTRAL; |
|
102 | + } |
|
103 | + } |
|
104 | 104 | } |
@@ -136,61 +136,61 @@ |
||
136 | 136 | * @since 0.3 |
137 | 137 | */ |
138 | 138 | class LoggerLayoutPattern extends LoggerLayout { |
139 | - /** Default conversion Pattern */ |
|
140 | - const DEFAULT_CONVERSION_PATTERN = '%m%n'; |
|
139 | + /** Default conversion Pattern */ |
|
140 | + const DEFAULT_CONVERSION_PATTERN = '%m%n'; |
|
141 | 141 | |
142 | - /** Default conversion TTCC Pattern */ |
|
143 | - const TTCC_CONVERSION_PATTERN = '%r [%t] %p %c %x - %m%n'; |
|
142 | + /** Default conversion TTCC Pattern */ |
|
143 | + const TTCC_CONVERSION_PATTERN = '%r [%t] %p %c %x - %m%n'; |
|
144 | 144 | |
145 | - /** The pattern. |
|
146 | - * @var string */ |
|
147 | - private $pattern; |
|
145 | + /** The pattern. |
|
146 | + * @var string */ |
|
147 | + private $pattern; |
|
148 | 148 | |
149 | - /** Head of a chain of Converters. |
|
150 | - * @var LoggerPatternConverter */ |
|
151 | - private $head; |
|
149 | + /** Head of a chain of Converters. |
|
150 | + * @var LoggerPatternConverter */ |
|
151 | + private $head; |
|
152 | 152 | |
153 | - private $timezone; |
|
153 | + private $timezone; |
|
154 | 154 | |
155 | - /** |
|
156 | - * Constructs a PatternLayout using the |
|
157 | - * {@link DEFAULT_LAYOUT_PATTERN}. |
|
158 | - * The default pattern just produces the application supplied message. |
|
159 | - */ |
|
160 | - public function __construct($pattern = null) { |
|
161 | - if ($pattern === null) { |
|
162 | - $this->pattern = self :: DEFAULT_CONVERSION_PATTERN; |
|
163 | - } else { |
|
164 | - $this->pattern = $pattern; |
|
165 | - } |
|
166 | - } |
|
155 | + /** |
|
156 | + * Constructs a PatternLayout using the |
|
157 | + * {@link DEFAULT_LAYOUT_PATTERN}. |
|
158 | + * The default pattern just produces the application supplied message. |
|
159 | + */ |
|
160 | + public function __construct($pattern = null) { |
|
161 | + if ($pattern === null) { |
|
162 | + $this->pattern = self :: DEFAULT_CONVERSION_PATTERN; |
|
163 | + } else { |
|
164 | + $this->pattern = $pattern; |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Set the <b>ConversionPattern</b> option. This is the string which |
|
170 | - * controls formatting and consists of a mix of literal content and |
|
171 | - * conversion specifiers. |
|
172 | - */ |
|
173 | - public function setConversionPattern($conversionPattern) { |
|
174 | - $this->pattern = $conversionPattern; |
|
175 | - $patternParser = new LoggerPatternParser($this->pattern); |
|
176 | - $this->head = $patternParser->parse(); |
|
177 | - } |
|
168 | + /** |
|
169 | + * Set the <b>ConversionPattern</b> option. This is the string which |
|
170 | + * controls formatting and consists of a mix of literal content and |
|
171 | + * conversion specifiers. |
|
172 | + */ |
|
173 | + public function setConversionPattern($conversionPattern) { |
|
174 | + $this->pattern = $conversionPattern; |
|
175 | + $patternParser = new LoggerPatternParser($this->pattern); |
|
176 | + $this->head = $patternParser->parse(); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Produces a formatted string as specified by the conversion pattern. |
|
181 | - * |
|
182 | - * @param LoggerLoggingEvent $event |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function format(LoggerLoggingEvent $event) { |
|
186 | - $sbuf = ''; |
|
187 | - $c = $this->head; |
|
188 | - while ($c !== null) { |
|
189 | - $c->format($sbuf, $event); |
|
190 | - $c = $c->next; |
|
191 | - } |
|
192 | - return $sbuf; |
|
193 | - } |
|
179 | + /** |
|
180 | + * Produces a formatted string as specified by the conversion pattern. |
|
181 | + * |
|
182 | + * @param LoggerLoggingEvent $event |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function format(LoggerLoggingEvent $event) { |
|
186 | + $sbuf = ''; |
|
187 | + $c = $this->head; |
|
188 | + while ($c !== null) { |
|
189 | + $c->format($sbuf, $event); |
|
190 | + $c = $c->next; |
|
191 | + } |
|
192 | + return $sbuf; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | /** |
196 | 196 | * Returns an array with the formatted elements. |
@@ -33,309 +33,309 @@ |
||
33 | 33 | */ |
34 | 34 | class LoggerPatternParser { |
35 | 35 | |
36 | - const ESCAPE_CHAR = '%'; |
|
36 | + const ESCAPE_CHAR = '%'; |
|
37 | 37 | |
38 | - const LITERAL_STATE = 0; |
|
39 | - const CONVERTER_STATE = 1; |
|
40 | - const MINUS_STATE = 2; |
|
41 | - const DOT_STATE = 3; |
|
42 | - const MIN_STATE = 4; |
|
43 | - const MAX_STATE = 5; |
|
38 | + const LITERAL_STATE = 0; |
|
39 | + const CONVERTER_STATE = 1; |
|
40 | + const MINUS_STATE = 2; |
|
41 | + const DOT_STATE = 3; |
|
42 | + const MIN_STATE = 4; |
|
43 | + const MAX_STATE = 5; |
|
44 | 44 | |
45 | - const FULL_LOCATION_CONVERTER = 1000; |
|
46 | - const METHOD_LOCATION_CONVERTER = 1001; |
|
47 | - const CLASS_LOCATION_CONVERTER = 1002; |
|
48 | - const FILE_LOCATION_CONVERTER = 1003; |
|
49 | - const LINE_LOCATION_CONVERTER = 1004; |
|
45 | + const FULL_LOCATION_CONVERTER = 1000; |
|
46 | + const METHOD_LOCATION_CONVERTER = 1001; |
|
47 | + const CLASS_LOCATION_CONVERTER = 1002; |
|
48 | + const FILE_LOCATION_CONVERTER = 1003; |
|
49 | + const LINE_LOCATION_CONVERTER = 1004; |
|
50 | 50 | |
51 | - const RELATIVE_TIME_CONVERTER = 2000; |
|
52 | - const THREAD_CONVERTER = 2001; |
|
53 | - const LEVEL_CONVERTER = 2002; |
|
54 | - const NDC_CONVERTER = 2003; |
|
55 | - const MESSAGE_CONVERTER = 2004; |
|
51 | + const RELATIVE_TIME_CONVERTER = 2000; |
|
52 | + const THREAD_CONVERTER = 2001; |
|
53 | + const LEVEL_CONVERTER = 2002; |
|
54 | + const NDC_CONVERTER = 2003; |
|
55 | + const MESSAGE_CONVERTER = 2004; |
|
56 | 56 | |
57 | - const DATE_FORMAT_ISO8601 = 'Y-m-d H:i:s,u'; |
|
58 | - const DATE_FORMAT_ABSOLUTE = 'H:i:s'; |
|
59 | - const DATE_FORMAT_DATE = 'd M Y H:i:s,u'; |
|
57 | + const DATE_FORMAT_ISO8601 = 'Y-m-d H:i:s,u'; |
|
58 | + const DATE_FORMAT_ABSOLUTE = 'H:i:s'; |
|
59 | + const DATE_FORMAT_DATE = 'd M Y H:i:s,u'; |
|
60 | 60 | |
61 | - private $state; |
|
62 | - private $currentLiteral; |
|
63 | - private $patternLength; |
|
64 | - private $i; |
|
61 | + private $state; |
|
62 | + private $currentLiteral; |
|
63 | + private $patternLength; |
|
64 | + private $i; |
|
65 | 65 | |
66 | - /** |
|
67 | - * @var LoggerPatternConverter |
|
68 | - */ |
|
69 | - private $head = null; |
|
66 | + /** |
|
67 | + * @var LoggerPatternConverter |
|
68 | + */ |
|
69 | + private $head = null; |
|
70 | 70 | |
71 | - /** |
|
72 | - * @var LoggerPatternConverter |
|
73 | - */ |
|
74 | - private $tail = null; |
|
71 | + /** |
|
72 | + * @var LoggerPatternConverter |
|
73 | + */ |
|
74 | + private $tail = null; |
|
75 | 75 | |
76 | - /** |
|
77 | - * @var LoggerFormattingInfo |
|
78 | - */ |
|
79 | - private $formattingInfo; |
|
76 | + /** |
|
77 | + * @var LoggerFormattingInfo |
|
78 | + */ |
|
79 | + private $formattingInfo; |
|
80 | 80 | |
81 | - /** |
|
82 | - * @var string pattern to parse |
|
83 | - */ |
|
84 | - private $pattern; |
|
81 | + /** |
|
82 | + * @var string pattern to parse |
|
83 | + */ |
|
84 | + private $pattern; |
|
85 | 85 | |
86 | - /** |
|
87 | - * Constructor |
|
88 | - * |
|
89 | - * @param string $pattern |
|
90 | - */ |
|
91 | - public function __construct($pattern) { |
|
92 | - $this->pattern = $pattern; |
|
93 | - $this->patternLength = strlen($pattern); |
|
94 | - $this->formattingInfo = new LoggerFormattingInfo(); |
|
95 | - $this->state = self::LITERAL_STATE; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Constructor |
|
88 | + * |
|
89 | + * @param string $pattern |
|
90 | + */ |
|
91 | + public function __construct($pattern) { |
|
92 | + $this->pattern = $pattern; |
|
93 | + $this->patternLength = strlen($pattern); |
|
94 | + $this->formattingInfo = new LoggerFormattingInfo(); |
|
95 | + $this->state = self::LITERAL_STATE; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @param LoggerPatternConverter $pc |
|
100 | - */ |
|
101 | - public function addToList($pc) { |
|
102 | - if($this->head == null) { |
|
103 | - $this->head = $pc; |
|
104 | - $this->tail = $this->head; |
|
105 | - } else { |
|
106 | - $this->tail->next = $pc; |
|
107 | - $this->tail = $this->tail->next; |
|
108 | - } |
|
109 | - } |
|
98 | + /** |
|
99 | + * @param LoggerPatternConverter $pc |
|
100 | + */ |
|
101 | + public function addToList($pc) { |
|
102 | + if($this->head == null) { |
|
103 | + $this->head = $pc; |
|
104 | + $this->tail = $this->head; |
|
105 | + } else { |
|
106 | + $this->tail->next = $pc; |
|
107 | + $this->tail = $this->tail->next; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function extractOption() { |
|
115 | - if(($this->i < $this->patternLength) and ($this->pattern{$this->i} == '{')) { |
|
116 | - $end = strpos($this->pattern, '}' , $this->i); |
|
117 | - if($end !== false) { |
|
118 | - $r = substr($this->pattern, ($this->i + 1), ($end - $this->i - 1)); |
|
119 | - $this->i= $end + 1; |
|
120 | - return $r; |
|
121 | - } |
|
122 | - } |
|
123 | - return null; |
|
124 | - } |
|
111 | + /** |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function extractOption() { |
|
115 | + if(($this->i < $this->patternLength) and ($this->pattern{$this->i} == '{')) { |
|
116 | + $end = strpos($this->pattern, '}' , $this->i); |
|
117 | + if($end !== false) { |
|
118 | + $r = substr($this->pattern, ($this->i + 1), ($end - $this->i - 1)); |
|
119 | + $this->i= $end + 1; |
|
120 | + return $r; |
|
121 | + } |
|
122 | + } |
|
123 | + return null; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * The option is expected to be in decimal and positive. In case of |
|
128 | - * error, zero is returned. |
|
129 | - */ |
|
130 | - public function extractPrecisionOption() { |
|
131 | - $opt = $this->extractOption(); |
|
132 | - $r = 0; |
|
133 | - if($opt !== null) { |
|
134 | - if(is_numeric($opt)) { |
|
135 | - $r = (int)$opt; |
|
136 | - if($r <= 0) { |
|
137 | - $r = 0; |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - return $r; |
|
142 | - } |
|
126 | + /** |
|
127 | + * The option is expected to be in decimal and positive. In case of |
|
128 | + * error, zero is returned. |
|
129 | + */ |
|
130 | + public function extractPrecisionOption() { |
|
131 | + $opt = $this->extractOption(); |
|
132 | + $r = 0; |
|
133 | + if($opt !== null) { |
|
134 | + if(is_numeric($opt)) { |
|
135 | + $r = (int)$opt; |
|
136 | + if($r <= 0) { |
|
137 | + $r = 0; |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + return $r; |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - /** Parser. |
|
146 | - * |
|
147 | - * @return LoggerPatternConverter Returns $this->head. |
|
148 | - */ |
|
149 | - public function parse() { |
|
150 | - $c = ''; |
|
151 | - $this->i = 0; |
|
152 | - $this->currentLiteral = ''; |
|
153 | - while($this->i < $this->patternLength) { |
|
154 | - $c = $this->pattern{$this->i++}; |
|
145 | + /** Parser. |
|
146 | + * |
|
147 | + * @return LoggerPatternConverter Returns $this->head. |
|
148 | + */ |
|
149 | + public function parse() { |
|
150 | + $c = ''; |
|
151 | + $this->i = 0; |
|
152 | + $this->currentLiteral = ''; |
|
153 | + while($this->i < $this->patternLength) { |
|
154 | + $c = $this->pattern{$this->i++}; |
|
155 | 155 | |
156 | - switch($this->state) { |
|
157 | - case self::LITERAL_STATE: |
|
158 | - // In literal state, the last char is always a literal. |
|
159 | - if($this->i == $this->patternLength) { |
|
160 | - $this->currentLiteral .= $c; |
|
161 | - continue; |
|
162 | - } |
|
163 | - if($c == self::ESCAPE_CHAR) { |
|
164 | - // peek at the next char. |
|
165 | - switch($this->pattern{$this->i}) { |
|
166 | - case self::ESCAPE_CHAR: |
|
167 | - $this->currentLiteral .= $c; |
|
168 | - $this->i++; // move pointer |
|
169 | - break; |
|
170 | - case 'n': |
|
171 | - $this->currentLiteral .= PHP_EOL; |
|
172 | - $this->i++; // move pointer |
|
173 | - break; |
|
174 | - default: |
|
175 | - if(strlen($this->currentLiteral) != 0) { |
|
176 | - $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
177 | - } |
|
178 | - $this->currentLiteral = $c; |
|
179 | - $this->state = self::CONVERTER_STATE; |
|
180 | - $this->formattingInfo->reset(); |
|
181 | - } |
|
182 | - } else { |
|
183 | - $this->currentLiteral .= $c; |
|
184 | - } |
|
185 | - break; |
|
186 | - case self::CONVERTER_STATE: |
|
187 | - $this->currentLiteral .= $c; |
|
188 | - switch($c) { |
|
189 | - case '-': |
|
190 | - $this->formattingInfo->leftAlign = true; |
|
191 | - break; |
|
192 | - case '.': |
|
193 | - $this->state = self::DOT_STATE; |
|
194 | - break; |
|
195 | - default: |
|
196 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
197 | - $this->formattingInfo->min = ord($c) - ord('0'); |
|
198 | - $this->state = self::MIN_STATE; |
|
199 | - } else { |
|
200 | - $this->finalizeConverter($c); |
|
201 | - } |
|
202 | - } // switch |
|
203 | - break; |
|
204 | - case self::MIN_STATE: |
|
205 | - $this->currentLiteral .= $c; |
|
206 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
207 | - $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0')); |
|
208 | - } else if ($c == '.') { |
|
209 | - $this->state = self::DOT_STATE; |
|
210 | - } else { |
|
211 | - $this->finalizeConverter($c); |
|
212 | - } |
|
213 | - break; |
|
214 | - case self::DOT_STATE: |
|
215 | - $this->currentLiteral .= $c; |
|
216 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
217 | - $this->formattingInfo->max = ord($c) - ord('0'); |
|
218 | - $this->state = self::MAX_STATE; |
|
219 | - } else { |
|
220 | - $this->state = self::LITERAL_STATE; |
|
221 | - } |
|
222 | - break; |
|
223 | - case self::MAX_STATE: |
|
224 | - $this->currentLiteral .= $c; |
|
225 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
226 | - $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0')); |
|
227 | - } else { |
|
228 | - $this->finalizeConverter($c); |
|
229 | - $this->state = self::LITERAL_STATE; |
|
230 | - } |
|
231 | - break; |
|
232 | - } // switch |
|
233 | - } // while |
|
234 | - if(strlen($this->currentLiteral) != 0) { |
|
235 | - $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
236 | - } |
|
237 | - return $this->head; |
|
238 | - } |
|
156 | + switch($this->state) { |
|
157 | + case self::LITERAL_STATE: |
|
158 | + // In literal state, the last char is always a literal. |
|
159 | + if($this->i == $this->patternLength) { |
|
160 | + $this->currentLiteral .= $c; |
|
161 | + continue; |
|
162 | + } |
|
163 | + if($c == self::ESCAPE_CHAR) { |
|
164 | + // peek at the next char. |
|
165 | + switch($this->pattern{$this->i}) { |
|
166 | + case self::ESCAPE_CHAR: |
|
167 | + $this->currentLiteral .= $c; |
|
168 | + $this->i++; // move pointer |
|
169 | + break; |
|
170 | + case 'n': |
|
171 | + $this->currentLiteral .= PHP_EOL; |
|
172 | + $this->i++; // move pointer |
|
173 | + break; |
|
174 | + default: |
|
175 | + if(strlen($this->currentLiteral) != 0) { |
|
176 | + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
177 | + } |
|
178 | + $this->currentLiteral = $c; |
|
179 | + $this->state = self::CONVERTER_STATE; |
|
180 | + $this->formattingInfo->reset(); |
|
181 | + } |
|
182 | + } else { |
|
183 | + $this->currentLiteral .= $c; |
|
184 | + } |
|
185 | + break; |
|
186 | + case self::CONVERTER_STATE: |
|
187 | + $this->currentLiteral .= $c; |
|
188 | + switch($c) { |
|
189 | + case '-': |
|
190 | + $this->formattingInfo->leftAlign = true; |
|
191 | + break; |
|
192 | + case '.': |
|
193 | + $this->state = self::DOT_STATE; |
|
194 | + break; |
|
195 | + default: |
|
196 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
197 | + $this->formattingInfo->min = ord($c) - ord('0'); |
|
198 | + $this->state = self::MIN_STATE; |
|
199 | + } else { |
|
200 | + $this->finalizeConverter($c); |
|
201 | + } |
|
202 | + } // switch |
|
203 | + break; |
|
204 | + case self::MIN_STATE: |
|
205 | + $this->currentLiteral .= $c; |
|
206 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
207 | + $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0')); |
|
208 | + } else if ($c == '.') { |
|
209 | + $this->state = self::DOT_STATE; |
|
210 | + } else { |
|
211 | + $this->finalizeConverter($c); |
|
212 | + } |
|
213 | + break; |
|
214 | + case self::DOT_STATE: |
|
215 | + $this->currentLiteral .= $c; |
|
216 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
217 | + $this->formattingInfo->max = ord($c) - ord('0'); |
|
218 | + $this->state = self::MAX_STATE; |
|
219 | + } else { |
|
220 | + $this->state = self::LITERAL_STATE; |
|
221 | + } |
|
222 | + break; |
|
223 | + case self::MAX_STATE: |
|
224 | + $this->currentLiteral .= $c; |
|
225 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
226 | + $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0')); |
|
227 | + } else { |
|
228 | + $this->finalizeConverter($c); |
|
229 | + $this->state = self::LITERAL_STATE; |
|
230 | + } |
|
231 | + break; |
|
232 | + } // switch |
|
233 | + } // while |
|
234 | + if(strlen($this->currentLiteral) != 0) { |
|
235 | + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
236 | + } |
|
237 | + return $this->head; |
|
238 | + } |
|
239 | 239 | |
240 | - public function finalizeConverter($c) { |
|
241 | - $pc = null; |
|
242 | - switch($c) { |
|
243 | - case 'c': |
|
244 | - $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
245 | - $this->currentLiteral = ''; |
|
246 | - break; |
|
247 | - case 'C': |
|
248 | - $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
249 | - $this->currentLiteral = ''; |
|
250 | - break; |
|
251 | - case 'd': |
|
252 | - $dateFormatStr = self::DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT; |
|
253 | - $dOpt = $this->extractOption(); |
|
240 | + public function finalizeConverter($c) { |
|
241 | + $pc = null; |
|
242 | + switch($c) { |
|
243 | + case 'c': |
|
244 | + $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
245 | + $this->currentLiteral = ''; |
|
246 | + break; |
|
247 | + case 'C': |
|
248 | + $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
249 | + $this->currentLiteral = ''; |
|
250 | + break; |
|
251 | + case 'd': |
|
252 | + $dateFormatStr = self::DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT; |
|
253 | + $dOpt = $this->extractOption(); |
|
254 | 254 | |
255 | - if($dOpt !== null) |
|
256 | - $dateFormatStr = $dOpt; |
|
255 | + if($dOpt !== null) |
|
256 | + $dateFormatStr = $dOpt; |
|
257 | 257 | |
258 | - if($dateFormatStr == 'ISO8601') { |
|
259 | - $df = self::DATE_FORMAT_ISO8601; |
|
260 | - } else if($dateFormatStr == 'ABSOLUTE') { |
|
261 | - $df = self::DATE_FORMAT_ABSOLUTE; |
|
262 | - } else if($dateFormatStr == 'DATE') { |
|
263 | - $df = self::DATE_FORMAT_DATE; |
|
264 | - } else { |
|
265 | - $df = $dateFormatStr; |
|
266 | - if($df == null) { |
|
267 | - $df = self::DATE_FORMAT_ISO8601; |
|
268 | - } |
|
269 | - } |
|
270 | - $pc = new LoggerDatePatternConverter($this->formattingInfo, $df); |
|
271 | - $this->currentLiteral = ''; |
|
272 | - break; |
|
273 | - case 'F': |
|
274 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FILE_LOCATION_CONVERTER); |
|
275 | - $this->currentLiteral = ''; |
|
276 | - break; |
|
277 | - case 'l': |
|
278 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FULL_LOCATION_CONVERTER); |
|
279 | - $this->currentLiteral = ''; |
|
280 | - break; |
|
281 | - case 'L': |
|
282 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::LINE_LOCATION_CONVERTER); |
|
283 | - $this->currentLiteral = ''; |
|
284 | - break; |
|
285 | - case 'm': |
|
286 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::MESSAGE_CONVERTER); |
|
287 | - $this->currentLiteral = ''; |
|
288 | - break; |
|
289 | - case 'M': |
|
290 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::METHOD_LOCATION_CONVERTER); |
|
291 | - $this->currentLiteral = ''; |
|
292 | - break; |
|
293 | - case 'p': |
|
294 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::LEVEL_CONVERTER); |
|
295 | - $this->currentLiteral = ''; |
|
296 | - break; |
|
297 | - case 'r': |
|
298 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::RELATIVE_TIME_CONVERTER); |
|
299 | - $this->currentLiteral = ''; |
|
300 | - break; |
|
301 | - case 't': |
|
302 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::THREAD_CONVERTER); |
|
303 | - $this->currentLiteral = ''; |
|
304 | - break; |
|
305 | - case 'u': |
|
306 | - if($this->i < $this->patternLength) { |
|
307 | - $cNext = $this->pattern{$this->i}; |
|
308 | - if(ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) { |
|
309 | - $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string)(ord($cNext) - ord('0'))); |
|
310 | - $this->currentLiteral = ''; |
|
311 | - $this->i++; |
|
312 | - } |
|
313 | - } |
|
314 | - break; |
|
315 | - case 'x': |
|
316 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::NDC_CONVERTER); |
|
317 | - $this->currentLiteral = ''; |
|
318 | - break; |
|
319 | - case 'X': |
|
320 | - $xOpt = $this->extractOption(); |
|
321 | - $pc = new LoggerMDCPatternConverter($this->formattingInfo, $xOpt); |
|
322 | - $this->currentLiteral = ''; |
|
323 | - break; |
|
324 | - default: |
|
325 | - $pc = new LoggerLiteralPatternConverter($this->currentLiteral); |
|
326 | - $this->currentLiteral = ''; |
|
327 | - } |
|
328 | - $this->addConverter($pc); |
|
329 | - } |
|
258 | + if($dateFormatStr == 'ISO8601') { |
|
259 | + $df = self::DATE_FORMAT_ISO8601; |
|
260 | + } else if($dateFormatStr == 'ABSOLUTE') { |
|
261 | + $df = self::DATE_FORMAT_ABSOLUTE; |
|
262 | + } else if($dateFormatStr == 'DATE') { |
|
263 | + $df = self::DATE_FORMAT_DATE; |
|
264 | + } else { |
|
265 | + $df = $dateFormatStr; |
|
266 | + if($df == null) { |
|
267 | + $df = self::DATE_FORMAT_ISO8601; |
|
268 | + } |
|
269 | + } |
|
270 | + $pc = new LoggerDatePatternConverter($this->formattingInfo, $df); |
|
271 | + $this->currentLiteral = ''; |
|
272 | + break; |
|
273 | + case 'F': |
|
274 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FILE_LOCATION_CONVERTER); |
|
275 | + $this->currentLiteral = ''; |
|
276 | + break; |
|
277 | + case 'l': |
|
278 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FULL_LOCATION_CONVERTER); |
|
279 | + $this->currentLiteral = ''; |
|
280 | + break; |
|
281 | + case 'L': |
|
282 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::LINE_LOCATION_CONVERTER); |
|
283 | + $this->currentLiteral = ''; |
|
284 | + break; |
|
285 | + case 'm': |
|
286 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::MESSAGE_CONVERTER); |
|
287 | + $this->currentLiteral = ''; |
|
288 | + break; |
|
289 | + case 'M': |
|
290 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::METHOD_LOCATION_CONVERTER); |
|
291 | + $this->currentLiteral = ''; |
|
292 | + break; |
|
293 | + case 'p': |
|
294 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::LEVEL_CONVERTER); |
|
295 | + $this->currentLiteral = ''; |
|
296 | + break; |
|
297 | + case 'r': |
|
298 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::RELATIVE_TIME_CONVERTER); |
|
299 | + $this->currentLiteral = ''; |
|
300 | + break; |
|
301 | + case 't': |
|
302 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::THREAD_CONVERTER); |
|
303 | + $this->currentLiteral = ''; |
|
304 | + break; |
|
305 | + case 'u': |
|
306 | + if($this->i < $this->patternLength) { |
|
307 | + $cNext = $this->pattern{$this->i}; |
|
308 | + if(ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) { |
|
309 | + $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string)(ord($cNext) - ord('0'))); |
|
310 | + $this->currentLiteral = ''; |
|
311 | + $this->i++; |
|
312 | + } |
|
313 | + } |
|
314 | + break; |
|
315 | + case 'x': |
|
316 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::NDC_CONVERTER); |
|
317 | + $this->currentLiteral = ''; |
|
318 | + break; |
|
319 | + case 'X': |
|
320 | + $xOpt = $this->extractOption(); |
|
321 | + $pc = new LoggerMDCPatternConverter($this->formattingInfo, $xOpt); |
|
322 | + $this->currentLiteral = ''; |
|
323 | + break; |
|
324 | + default: |
|
325 | + $pc = new LoggerLiteralPatternConverter($this->currentLiteral); |
|
326 | + $this->currentLiteral = ''; |
|
327 | + } |
|
328 | + $this->addConverter($pc); |
|
329 | + } |
|
330 | 330 | |
331 | - public function addConverter($pc) { |
|
332 | - $this->currentLiteral = ''; |
|
333 | - // Add the pattern converter to the list. |
|
334 | - $this->addToList($pc); |
|
335 | - // Next pattern is assumed to be a literal. |
|
336 | - $this->state = self::LITERAL_STATE; |
|
337 | - // Reset formatting info |
|
338 | - $this->formattingInfo->reset(); |
|
339 | - } |
|
331 | + public function addConverter($pc) { |
|
332 | + $this->currentLiteral = ''; |
|
333 | + // Add the pattern converter to the list. |
|
334 | + $this->addToList($pc); |
|
335 | + // Next pattern is assumed to be a literal. |
|
336 | + $this->state = self::LITERAL_STATE; |
|
337 | + // Reset formatting info |
|
338 | + $this->formattingInfo->reset(); |
|
339 | + } |
|
340 | 340 | } |
341 | 341 |
@@ -24,27 +24,27 @@ |
||
24 | 24 | */ |
25 | 25 | class LoggerMDCPatternConverter extends LoggerPatternConverter { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - private $key; |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + private $key; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor |
|
34 | - * |
|
35 | - * @param string $formattingInfo |
|
36 | - * @param string $key |
|
37 | - */ |
|
38 | - public function __construct($formattingInfo, $key) { |
|
39 | - parent::__construct($formattingInfo); |
|
40 | - $this->key = $key; |
|
41 | - } |
|
32 | + /** |
|
33 | + * Constructor |
|
34 | + * |
|
35 | + * @param string $formattingInfo |
|
36 | + * @param string $key |
|
37 | + */ |
|
38 | + public function __construct($formattingInfo, $key) { |
|
39 | + parent::__construct($formattingInfo); |
|
40 | + $this->key = $key; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param LoggerLoggingEvent $event |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function convert($event) { |
|
48 | - return $event->getMDC($this->key); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @param LoggerLoggingEvent $event |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function convert($event) { |
|
48 | + return $event->getMDC($this->key); |
|
49 | + } |
|
50 | 50 | } |