@@ -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 | * This is a very simple filter based on string matching. |
@@ -47,43 +47,43 @@ discard block |
||
47 | 47 | */ |
48 | 48 | class LoggerFilterStringMatch extends LoggerFilter { |
49 | 49 | |
50 | - /** |
|
51 | - * @var boolean |
|
52 | - */ |
|
53 | - private $acceptOnMatch = true; |
|
50 | + /** |
|
51 | + * @var boolean |
|
52 | + */ |
|
53 | + private $acceptOnMatch = true; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - private $stringToMatch = null; |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + private $stringToMatch = null; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param mixed $acceptOnMatch a boolean or a string ('true' or 'false') |
|
62 | - */ |
|
63 | - public function setAcceptOnMatch($acceptOnMatch) { |
|
64 | - $this->acceptOnMatch = is_bool($acceptOnMatch) ? $acceptOnMatch : (bool)(strtolower($acceptOnMatch) == 'true'); |
|
65 | - } |
|
60 | + /** |
|
61 | + * @param mixed $acceptOnMatch a boolean or a string ('true' or 'false') |
|
62 | + */ |
|
63 | + public function setAcceptOnMatch($acceptOnMatch) { |
|
64 | + $this->acceptOnMatch = is_bool($acceptOnMatch) ? $acceptOnMatch : (bool)(strtolower($acceptOnMatch) == 'true'); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param string $s the string to match |
|
69 | - */ |
|
70 | - public function setStringToMatch($s) { |
|
71 | - $this->stringToMatch = $s; |
|
72 | - } |
|
67 | + /** |
|
68 | + * @param string $s the string to match |
|
69 | + */ |
|
70 | + public function setStringToMatch($s) { |
|
71 | + $this->stringToMatch = $s; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match. |
|
76 | - */ |
|
77 | - public function decide(LoggerLoggingEvent $event) { |
|
78 | - $msg = $event->getRenderedMessage(); |
|
74 | + /** |
|
75 | + * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match. |
|
76 | + */ |
|
77 | + public function decide(LoggerLoggingEvent $event) { |
|
78 | + $msg = $event->getRenderedMessage(); |
|
79 | 79 | |
80 | - if($msg === null or $this->stringToMatch === null) { |
|
81 | - return LoggerFilter::NEUTRAL; |
|
82 | - } |
|
80 | + if($msg === null or $this->stringToMatch === null) { |
|
81 | + return LoggerFilter::NEUTRAL; |
|
82 | + } |
|
83 | 83 | |
84 | - if(strpos($msg, $this->stringToMatch) !== false ) { |
|
85 | - return ($this->acceptOnMatch) ? LoggerFilter::ACCEPT : LoggerFilter::DENY; |
|
86 | - } |
|
87 | - return LoggerFilter::NEUTRAL; |
|
88 | - } |
|
84 | + if(strpos($msg, $this->stringToMatch) !== false ) { |
|
85 | + return ($this->acceptOnMatch) ? LoggerFilter::ACCEPT : LoggerFilter::DENY; |
|
86 | + } |
|
87 | + return LoggerFilter::NEUTRAL; |
|
88 | + } |
|
89 | 89 | } |
@@ -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 | * LoggerConfiguratorPhp class |
@@ -38,97 +38,97 @@ discard block |
||
38 | 38 | */ |
39 | 39 | class LoggerConfiguratorPhp implements LoggerConfigurator { |
40 | 40 | |
41 | - public function configure(LoggerHierarchy $hierarchy, $url = '') { |
|
42 | - return $this->doConfigure($url, $hierarchy); |
|
43 | - } |
|
41 | + public function configure(LoggerHierarchy $hierarchy, $url = '') { |
|
42 | + return $this->doConfigure($url, $hierarchy); |
|
43 | + } |
|
44 | 44 | |
45 | - private function doConfigure($url, LoggerHierarchy $hierarchy) { |
|
45 | + private function doConfigure($url, LoggerHierarchy $hierarchy) { |
|
46 | 46 | |
47 | - $config = require $url; |
|
47 | + $config = require $url; |
|
48 | 48 | |
49 | - // set threshold |
|
50 | - if(isset($config['threshold'])) { |
|
51 | - $hierarchy->setThreshold(LoggerOptionConverter::toLevel($config['threshold'], LoggerLevel::getLevelAll())); |
|
52 | - } |
|
49 | + // set threshold |
|
50 | + if(isset($config['threshold'])) { |
|
51 | + $hierarchy->setThreshold(LoggerOptionConverter::toLevel($config['threshold'], LoggerLevel::getLevelAll())); |
|
52 | + } |
|
53 | 53 | |
54 | - // parse and create appenders |
|
55 | - if(isset($config['appenders'])) { |
|
54 | + // parse and create appenders |
|
55 | + if(isset($config['appenders'])) { |
|
56 | 56 | |
57 | - foreach($config['appenders'] as $appenderName => $appenderProperties) { |
|
57 | + foreach($config['appenders'] as $appenderName => $appenderProperties) { |
|
58 | 58 | |
59 | - $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderProperties['class']); |
|
59 | + $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderProperties['class']); |
|
60 | 60 | |
61 | - if($appender->requiresLayout()) { |
|
61 | + if($appender->requiresLayout()) { |
|
62 | 62 | |
63 | - if(isset($appenderProperties['layout'])) { |
|
63 | + if(isset($appenderProperties['layout'])) { |
|
64 | 64 | |
65 | - if(isset($appenderProperties['layout']['class']) and !empty($appenderProperties['layout']['class'])) { |
|
66 | - $layoutClass = $appenderProperties['layout']['class']; |
|
67 | - } else { |
|
68 | - $layoutClass = 'LoggerLayoutSimple'; |
|
69 | - } |
|
65 | + if(isset($appenderProperties['layout']['class']) and !empty($appenderProperties['layout']['class'])) { |
|
66 | + $layoutClass = $appenderProperties['layout']['class']; |
|
67 | + } else { |
|
68 | + $layoutClass = 'LoggerLayoutSimple'; |
|
69 | + } |
|
70 | 70 | |
71 | - $layout = LoggerReflectionUtils::createObject($layoutClass); |
|
72 | - if($layout === null) { |
|
73 | - $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
74 | - } |
|
71 | + $layout = LoggerReflectionUtils::createObject($layoutClass); |
|
72 | + if($layout === null) { |
|
73 | + $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
74 | + } |
|
75 | 75 | |
76 | - if($layout instanceof LoggerLayoutPattern) { |
|
77 | - $layout->setConversionPattern($appenderProperties['layout']['conversionPattern']); |
|
78 | - } |
|
76 | + if($layout instanceof LoggerLayoutPattern) { |
|
77 | + $layout->setConversionPattern($appenderProperties['layout']['conversionPattern']); |
|
78 | + } |
|
79 | 79 | |
80 | - $appender->setLayout($layout); |
|
80 | + $appender->setLayout($layout); |
|
81 | 81 | |
82 | - } else { |
|
83 | - // TODO: throw exception? |
|
84 | - } |
|
82 | + } else { |
|
83 | + // TODO: throw exception? |
|
84 | + } |
|
85 | 85 | |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - // parse and create root logger |
|
93 | - if(isset($config['rootLogger'])) { |
|
94 | - $rootLogger = $hierarchy->getRootLogger(); |
|
95 | - if(isset($config['rootLogger']['level'])) { |
|
96 | - $rootLogger->setLevel(LoggerOptionConverter::toLevel($config['rootLogger']['level'], LoggerLevel::getLevelDebug())); |
|
97 | - if(isset($config['rootLogger']['appenders'])) { |
|
98 | - foreach($config['rootLogger']['appenders'] as $appenderName) { |
|
99 | - $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
100 | - if($appender !== null) { |
|
101 | - $rootLogger->addAppender($appender); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
92 | + // parse and create root logger |
|
93 | + if(isset($config['rootLogger'])) { |
|
94 | + $rootLogger = $hierarchy->getRootLogger(); |
|
95 | + if(isset($config['rootLogger']['level'])) { |
|
96 | + $rootLogger->setLevel(LoggerOptionConverter::toLevel($config['rootLogger']['level'], LoggerLevel::getLevelDebug())); |
|
97 | + if(isset($config['rootLogger']['appenders'])) { |
|
98 | + foreach($config['rootLogger']['appenders'] as $appenderName) { |
|
99 | + $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
100 | + if($appender !== null) { |
|
101 | + $rootLogger->addAppender($appender); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - // parse and create loggers |
|
109 | - if(isset($config['loggers'])) { |
|
110 | - foreach($config['loggers'] as $loggerName => $loggerProperties) { |
|
111 | - if(is_string($loggerName)) { |
|
112 | - $logger = $hierarchy->getLogger($loggerName); |
|
108 | + // parse and create loggers |
|
109 | + if(isset($config['loggers'])) { |
|
110 | + foreach($config['loggers'] as $loggerName => $loggerProperties) { |
|
111 | + if(is_string($loggerName)) { |
|
112 | + $logger = $hierarchy->getLogger($loggerName); |
|
113 | 113 | |
114 | - if(isset($loggerProperties['level'])) { |
|
115 | - $logger->setLevel(LoggerOptionConverter::toLevel($loggerProperties['level'], LoggerLevel::getLevelDebug())); |
|
116 | - if(isset($loggerProperties['appenders'])) { |
|
117 | - foreach($loggerProperties['appenders'] as $appenderName) { |
|
118 | - $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
119 | - if($appender !== null) { |
|
120 | - $logger->addAppender($appender); |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } else { |
|
126 | - // TODO: throw exception |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
114 | + if(isset($loggerProperties['level'])) { |
|
115 | + $logger->setLevel(LoggerOptionConverter::toLevel($loggerProperties['level'], LoggerLevel::getLevelDebug())); |
|
116 | + if(isset($loggerProperties['appenders'])) { |
|
117 | + foreach($loggerProperties['appenders'] as $appenderName) { |
|
118 | + $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
119 | + if($appender !== null) { |
|
120 | + $logger->addAppender($appender); |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } else { |
|
126 | + // TODO: throw exception |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - return true; |
|
132 | - } |
|
131 | + return true; |
|
132 | + } |
|
133 | 133 | |
134 | 134 | } |
@@ -31,17 +31,17 @@ |
||
31 | 31 | */ |
32 | 32 | class LoggerConfiguratorBasic implements LoggerConfigurator { |
33 | 33 | |
34 | - /** |
|
35 | - * Add a {@link LoggerAppenderConsole} that uses |
|
36 | - * the {@link LoggerLayoutTTCC} to the root category. |
|
37 | - * |
|
38 | - * @param string $url not used here |
|
39 | - */ |
|
40 | - public function configure(LoggerHierarchy $hierarchy, $url = null) { |
|
41 | - $root = $hierarchy->getRootLogger(); |
|
42 | - $appender = new LoggerAppenderConsole('A1'); |
|
43 | - $appender->setLayout( new LoggerLayoutTTCC() ); |
|
44 | - $appender->activateOptions(); |
|
45 | - $root->addAppender($appender); |
|
46 | - } |
|
34 | + /** |
|
35 | + * Add a {@link LoggerAppenderConsole} that uses |
|
36 | + * the {@link LoggerLayoutTTCC} to the root category. |
|
37 | + * |
|
38 | + * @param string $url not used here |
|
39 | + */ |
|
40 | + public function configure(LoggerHierarchy $hierarchy, $url = null) { |
|
41 | + $root = $hierarchy->getRootLogger(); |
|
42 | + $appender = new LoggerAppenderConsole('A1'); |
|
43 | + $appender->setLayout( new LoggerLayoutTTCC() ); |
|
44 | + $appender->activateOptions(); |
|
45 | + $root->addAppender($appender); |
|
46 | + } |
|
47 | 47 | } |
@@ -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 | * Allows the configuration of log4php from an external file. |
@@ -63,401 +63,401 @@ discard block |
||
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 | } |
@@ -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 | * Use this class to initialize the log4php environment using XML files. |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | * @since 0.4 |
45 | 45 | */ |
46 | 46 | class LoggerConfiguratorXml implements LoggerConfigurator { |
47 | - const APPENDER_STATE = 1000; |
|
48 | - const LAYOUT_STATE = 1010; |
|
49 | - const ROOT_STATE = 1020; |
|
50 | - const LOGGER_STATE = 1030; |
|
51 | - const FILTER_STATE = 1040; |
|
47 | + const APPENDER_STATE = 1000; |
|
48 | + const LAYOUT_STATE = 1010; |
|
49 | + const ROOT_STATE = 1020; |
|
50 | + const LOGGER_STATE = 1030; |
|
51 | + const FILTER_STATE = 1040; |
|
52 | 52 | |
53 | - const DEFAULT_FILENAME = './log4php.xml'; |
|
53 | + const DEFAULT_FILENAME = './log4php.xml'; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string the default configuration document |
|
57 | - */ |
|
58 | - const DEFAULT_CONFIGURATION = |
|
59 | - '<?xml version="1.0" ?> |
|
55 | + /** |
|
56 | + * @var string the default configuration document |
|
57 | + */ |
|
58 | + const DEFAULT_CONFIGURATION = |
|
59 | + '<?xml version="1.0" ?> |
|
60 | 60 | <log4php:configuration threshold="all"> |
61 | 61 | <appender name="A1" class="LoggerAppenderEcho"> |
62 | 62 | <layout class="LoggerLayoutSimple" /> |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | </root> |
68 | 68 | </log4php:configuration>'; |
69 | 69 | |
70 | - /** |
|
71 | - * @var string the elements namespace |
|
72 | - */ |
|
73 | - const XMLNS = 'HTTP://LOGGING.APACHE.ORG/LOG4PHP/'; |
|
70 | + /** |
|
71 | + * @var string the elements namespace |
|
72 | + */ |
|
73 | + const XMLNS = 'HTTP://LOGGING.APACHE.ORG/LOG4PHP/'; |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @var LoggerHierarchy |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Extend this abstract class to create your own log layout format. |
@@ -26,45 +26,45 @@ discard block |
||
26 | 26 | * @abstract |
27 | 27 | */ |
28 | 28 | abstract class LoggerLayout { |
29 | - /** |
|
30 | - * Activates options for this layout. |
|
31 | - * Override this method if you have options to be activated. |
|
32 | - */ |
|
33 | - public function activateOptions() { |
|
34 | - return true; |
|
35 | - } |
|
29 | + /** |
|
30 | + * Activates options for this layout. |
|
31 | + * Override this method if you have options to be activated. |
|
32 | + */ |
|
33 | + public function activateOptions() { |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Override this method to create your own layout format. |
|
39 | - * |
|
40 | - * @param LoggerLoggingEvent |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function format(LoggerLoggingEvent $event) { |
|
44 | - return $event->getRenderedMessage(); |
|
45 | - } |
|
37 | + /** |
|
38 | + * Override this method to create your own layout format. |
|
39 | + * |
|
40 | + * @param LoggerLoggingEvent |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function format(LoggerLoggingEvent $event) { |
|
44 | + return $event->getRenderedMessage(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Returns the content type output by this layout. |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getContentType() { |
|
52 | - return "text/plain"; |
|
53 | - } |
|
47 | + /** |
|
48 | + * Returns the content type output by this layout. |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getContentType() { |
|
52 | + return "text/plain"; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the footer for the layout format. |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function getFooter() { |
|
60 | - return null; |
|
61 | - } |
|
55 | + /** |
|
56 | + * Returns the footer for the layout format. |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function getFooter() { |
|
60 | + return null; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Returns the header for the layout format. |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getHeader() { |
|
68 | - return null; |
|
69 | - } |
|
63 | + /** |
|
64 | + * Returns the header for the layout format. |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getHeader() { |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Log objects using customized renderers that implement {@link LoggerRendererObject}. |
@@ -36,114 +36,114 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class LoggerRendererMap { |
38 | 38 | |
39 | - /** |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $map; |
|
39 | + /** |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $map; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var LoggerDefaultRenderer |
|
46 | - */ |
|
47 | - private $defaultRenderer; |
|
44 | + /** |
|
45 | + * @var LoggerDefaultRenderer |
|
46 | + */ |
|
47 | + private $defaultRenderer; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Constructor |
|
51 | - */ |
|
52 | - public function __construct() { |
|
53 | - $this->map = array(); |
|
54 | - $this->defaultRenderer = new LoggerRendererDefault(); |
|
55 | - } |
|
49 | + /** |
|
50 | + * Constructor |
|
51 | + */ |
|
52 | + public function __construct() { |
|
53 | + $this->map = array(); |
|
54 | + $this->defaultRenderer = new LoggerRendererDefault(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Add a renderer to a hierarchy passed as parameter. |
|
59 | - * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
60 | - * |
|
61 | - * @param LoggerHierarchy $repository a logger repository. |
|
62 | - * @param string $renderedClassName |
|
63 | - * @param string $renderingClassName |
|
64 | - * @static |
|
65 | - */ |
|
66 | - public function addRenderer($renderedClassName, $renderingClassName) { |
|
67 | - $renderer = LoggerReflectionUtils::createObject($renderingClassName); |
|
68 | - if($renderer == null) { |
|
69 | - return; |
|
70 | - } else { |
|
71 | - $this->put($renderedClassName, $renderer); |
|
72 | - } |
|
73 | - } |
|
57 | + /** |
|
58 | + * Add a renderer to a hierarchy passed as parameter. |
|
59 | + * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
60 | + * |
|
61 | + * @param LoggerHierarchy $repository a logger repository. |
|
62 | + * @param string $renderedClassName |
|
63 | + * @param string $renderingClassName |
|
64 | + * @static |
|
65 | + */ |
|
66 | + public function addRenderer($renderedClassName, $renderingClassName) { |
|
67 | + $renderer = LoggerReflectionUtils::createObject($renderingClassName); |
|
68 | + if($renderer == null) { |
|
69 | + return; |
|
70 | + } else { |
|
71 | + $this->put($renderedClassName, $renderer); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Find the appropriate renderer for the class type of the |
|
78 | - * <var>o</var> parameter. |
|
79 | - * |
|
80 | - * This is accomplished by calling the {@link getByObject()} |
|
81 | - * method if <var>o</var> is object or using {@link LoggerRendererDefault}. |
|
82 | - * Once a renderer is found, it is applied on the object <var>o</var> and |
|
83 | - * the result is returned as a string. |
|
84 | - * |
|
85 | - * @param mixed $o |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function findAndRender($o) { |
|
89 | - if($o == null) { |
|
90 | - return null; |
|
91 | - } else { |
|
92 | - if(is_object($o)) { |
|
93 | - $renderer = $this->getByObject($o); |
|
94 | - if($renderer !== null) { |
|
95 | - return $renderer->render($o); |
|
96 | - } else { |
|
97 | - return null; |
|
98 | - } |
|
99 | - } else { |
|
100 | - $renderer = $this->defaultRenderer; |
|
101 | - return $renderer->render($o); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
76 | + /** |
|
77 | + * Find the appropriate renderer for the class type of the |
|
78 | + * <var>o</var> parameter. |
|
79 | + * |
|
80 | + * This is accomplished by calling the {@link getByObject()} |
|
81 | + * method if <var>o</var> is object or using {@link LoggerRendererDefault}. |
|
82 | + * Once a renderer is found, it is applied on the object <var>o</var> and |
|
83 | + * the result is returned as a string. |
|
84 | + * |
|
85 | + * @param mixed $o |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function findAndRender($o) { |
|
89 | + if($o == null) { |
|
90 | + return null; |
|
91 | + } else { |
|
92 | + if(is_object($o)) { |
|
93 | + $renderer = $this->getByObject($o); |
|
94 | + if($renderer !== null) { |
|
95 | + return $renderer->render($o); |
|
96 | + } else { |
|
97 | + return null; |
|
98 | + } |
|
99 | + } else { |
|
100 | + $renderer = $this->defaultRenderer; |
|
101 | + return $renderer->render($o); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
108 | - * class of the object parameter. |
|
109 | - * |
|
110 | - * @param mixed $o |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function getByObject($o) { |
|
114 | - return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
115 | - } |
|
106 | + /** |
|
107 | + * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
108 | + * class of the object parameter. |
|
109 | + * |
|
110 | + * @param mixed $o |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function getByObject($o) { |
|
114 | + return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * Search the parents of <var>clazz</var> for a renderer. |
|
120 | - * |
|
121 | - * The renderer closest in the hierarchy will be returned. If no |
|
122 | - * renderers could be found, then the default renderer is returned. |
|
123 | - * |
|
124 | - * @param string $class |
|
125 | - * @return LoggerRendererObject |
|
126 | - */ |
|
127 | - public function getByClassName($class) { |
|
128 | - $r = null; |
|
129 | - for($c = strtolower($class); !empty($c); $c = get_parent_class($c)) { |
|
130 | - if(isset($this->map[$c])) { |
|
131 | - return $this->map[$c]; |
|
132 | - } |
|
133 | - } |
|
134 | - return $this->defaultRenderer; |
|
135 | - } |
|
118 | + /** |
|
119 | + * Search the parents of <var>clazz</var> for a renderer. |
|
120 | + * |
|
121 | + * The renderer closest in the hierarchy will be returned. If no |
|
122 | + * renderers could be found, then the default renderer is returned. |
|
123 | + * |
|
124 | + * @param string $class |
|
125 | + * @return LoggerRendererObject |
|
126 | + */ |
|
127 | + public function getByClassName($class) { |
|
128 | + $r = null; |
|
129 | + for($c = strtolower($class); !empty($c); $c = get_parent_class($c)) { |
|
130 | + if(isset($this->map[$c])) { |
|
131 | + return $this->map[$c]; |
|
132 | + } |
|
133 | + } |
|
134 | + return $this->defaultRenderer; |
|
135 | + } |
|
136 | 136 | |
137 | - public function clear() { |
|
138 | - $this->map = array(); |
|
139 | - } |
|
137 | + public function clear() { |
|
138 | + $this->map = array(); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * Register a {@link LoggerRendererObject} for <var>clazz</var>. |
|
143 | - * @param string $class |
|
144 | - * @param LoggerRendererObject $or |
|
145 | - */ |
|
146 | - private function put($class, $or) { |
|
147 | - $this->map[strtolower($class)] = $or; |
|
148 | - } |
|
141 | + /** |
|
142 | + * Register a {@link LoggerRendererObject} for <var>clazz</var>. |
|
143 | + * @param string $class |
|
144 | + * @param LoggerRendererObject $or |
|
145 | + */ |
|
146 | + private function put($class, $or) { |
|
147 | + $this->map[strtolower($class)] = $or; |
|
148 | + } |
|
149 | 149 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * The default Renderer renders objects by type casting. |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | */ |
40 | 40 | class LoggerRendererDefault implements LoggerRendererObject { |
41 | 41 | |
42 | - /** |
|
43 | - * Render objects by type casting |
|
44 | - * |
|
45 | - * @param mixed $o the object to render |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function render($o) { |
|
49 | - return var_export($o, true); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Render objects by type casting |
|
44 | + * |
|
45 | + * @param mixed $o the object to render |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function render($o) { |
|
49 | + return var_export($o, true); |
|
50 | + } |
|
51 | 51 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | - * contributor license agreements. See the NOTICE file distributed with |
|
5 | - * this work for additional information regarding copyright ownership. |
|
6 | - * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | - * (the "License"); you may not use this file except in compliance with |
|
8 | - * the License. You may obtain a copy of the License at |
|
9 | - * |
|
10 | - * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | - * |
|
12 | - * Unless required by applicable law or agreed to in writing, software |
|
13 | - * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | - * See the License for the specific language governing permissions and |
|
16 | - * limitations under the License. |
|
17 | - * |
|
18 | - * @package log4php |
|
19 | - */ |
|
3 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | + * contributor license agreements. See the NOTICE file distributed with |
|
5 | + * this work for additional information regarding copyright ownership. |
|
6 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | + * (the "License"); you may not use this file except in compliance with |
|
8 | + * the License. You may obtain a copy of the License at |
|
9 | + * |
|
10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | + * |
|
12 | + * Unless required by applicable law or agreed to in writing, software |
|
13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | + * See the License for the specific language governing permissions and |
|
16 | + * limitations under the License. |
|
17 | + * |
|
18 | + * @package log4php |
|
19 | + */ |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Implement this interface in order to render objects as strings using {@link LoggerRendererMap}. |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | * @since 0.3 |
38 | 38 | */ |
39 | 39 | interface LoggerRendererObject { |
40 | - /** |
|
41 | - * Render the entity passed as parameter as a String. |
|
42 | - * @param mixed $o entity to render |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function render($o); |
|
40 | + /** |
|
41 | + * Render the entity passed as parameter as a String. |
|
42 | + * @param mixed $o entity to render |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function render($o); |
|
46 | 46 | } |