@@ -18,123 +18,123 @@ |
||
18 | 18 | * @package log4php |
19 | 19 | */ |
20 | 20 | |
21 | - /** |
|
22 | - * Provides methods for reflective use on php objects |
|
23 | - * @package log4php |
|
24 | - */ |
|
21 | + /** |
|
22 | + * Provides methods for reflective use on php objects |
|
23 | + * @package log4php |
|
24 | + */ |
|
25 | 25 | class LoggerReflectionUtils { |
26 | - /** the target object */ |
|
27 | - private $obj; |
|
26 | + /** the target object */ |
|
27 | + private $obj; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Create a new LoggerReflectionUtils for the specified Object. |
|
31 | - * This is done in prepartion for invoking {@link setProperty()} |
|
32 | - * one or more times. |
|
33 | - * @param object &$obj the object for which to set properties |
|
34 | - */ |
|
35 | - public function __construct($obj) { |
|
36 | - $this->obj = $obj; |
|
37 | - } |
|
29 | + /** |
|
30 | + * Create a new LoggerReflectionUtils for the specified Object. |
|
31 | + * This is done in prepartion for invoking {@link setProperty()} |
|
32 | + * one or more times. |
|
33 | + * @param object &$obj the object for which to set properties |
|
34 | + */ |
|
35 | + public function __construct($obj) { |
|
36 | + $this->obj = $obj; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Set the properties of an object passed as a parameter in one |
|
41 | - * go. The <code>properties</code> are parsed relative to a |
|
42 | - * <code>prefix</code>. |
|
43 | - * |
|
44 | - * @param object $obj The object to configure. |
|
45 | - * @param array $properties An array containing keys and values. |
|
46 | - * @param string $prefix Only keys having the specified prefix will be set. |
|
47 | - * @static |
|
48 | - */ |
|
49 | - // TODO: check, if this is really useful |
|
50 | - public static function setPropertiesByObject($obj, $properties, $prefix) { |
|
51 | - $pSetter = new LoggerReflectionUtils($obj); |
|
52 | - return $pSetter->setProperties($properties, $prefix); |
|
53 | - } |
|
39 | + /** |
|
40 | + * Set the properties of an object passed as a parameter in one |
|
41 | + * go. The <code>properties</code> are parsed relative to a |
|
42 | + * <code>prefix</code>. |
|
43 | + * |
|
44 | + * @param object $obj The object to configure. |
|
45 | + * @param array $properties An array containing keys and values. |
|
46 | + * @param string $prefix Only keys having the specified prefix will be set. |
|
47 | + * @static |
|
48 | + */ |
|
49 | + // TODO: check, if this is really useful |
|
50 | + public static function setPropertiesByObject($obj, $properties, $prefix) { |
|
51 | + $pSetter = new LoggerReflectionUtils($obj); |
|
52 | + return $pSetter->setProperties($properties, $prefix); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Set the properites for the object that match the |
|
58 | - * <code>prefix</code> passed as parameter. |
|
59 | - * |
|
60 | - * Example: |
|
61 | - * |
|
62 | - * $arr['xxxname'] = 'Joe'; |
|
63 | - * $arr['xxxmale'] = true; |
|
64 | - * and prefix xxx causes setName and setMale. |
|
65 | - * |
|
66 | - * @param array $properties An array containing keys and values. |
|
67 | - * @param string $prefix Only keys having the specified prefix will be set. |
|
68 | - */ |
|
69 | - // TODO: check, if this is really useful |
|
70 | - public function setProperties($properties, $prefix) { |
|
71 | - $len = strlen($prefix); |
|
72 | - while(list($key,) = each($properties)) { |
|
73 | - if(strpos($key, $prefix) === 0) { |
|
74 | - if(strpos($key, '.', ($len + 1)) > 0) { |
|
75 | - continue; |
|
76 | - } |
|
77 | - $value = LoggerOptionConverter::findAndSubst($key, $properties); |
|
78 | - $key = substr($key, $len); |
|
79 | - if($key == 'layout' and ($this->obj instanceof LoggerAppender)) { |
|
80 | - continue; |
|
81 | - } |
|
82 | - $this->setProperty($key, $value); |
|
83 | - } |
|
84 | - } |
|
85 | - $this->activate(); |
|
86 | - } |
|
56 | + /** |
|
57 | + * Set the properites for the object that match the |
|
58 | + * <code>prefix</code> passed as parameter. |
|
59 | + * |
|
60 | + * Example: |
|
61 | + * |
|
62 | + * $arr['xxxname'] = 'Joe'; |
|
63 | + * $arr['xxxmale'] = true; |
|
64 | + * and prefix xxx causes setName and setMale. |
|
65 | + * |
|
66 | + * @param array $properties An array containing keys and values. |
|
67 | + * @param string $prefix Only keys having the specified prefix will be set. |
|
68 | + */ |
|
69 | + // TODO: check, if this is really useful |
|
70 | + public function setProperties($properties, $prefix) { |
|
71 | + $len = strlen($prefix); |
|
72 | + while(list($key,) = each($properties)) { |
|
73 | + if(strpos($key, $prefix) === 0) { |
|
74 | + if(strpos($key, '.', ($len + 1)) > 0) { |
|
75 | + continue; |
|
76 | + } |
|
77 | + $value = LoggerOptionConverter::findAndSubst($key, $properties); |
|
78 | + $key = substr($key, $len); |
|
79 | + if($key == 'layout' and ($this->obj instanceof LoggerAppender)) { |
|
80 | + continue; |
|
81 | + } |
|
82 | + $this->setProperty($key, $value); |
|
83 | + } |
|
84 | + } |
|
85 | + $this->activate(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Set a property on this PropertySetter's Object. If successful, this |
|
90 | - * method will invoke a setter method on the underlying Object. The |
|
91 | - * setter is the one for the specified property name and the value is |
|
92 | - * determined partly from the setter argument type and partly from the |
|
93 | - * value specified in the call to this method. |
|
94 | - * |
|
95 | - * <p>If the setter expects a String no conversion is necessary. |
|
96 | - * If it expects an int, then an attempt is made to convert 'value' |
|
97 | - * to an int using new Integer(value). If the setter expects a boolean, |
|
98 | - * the conversion is by new Boolean(value). |
|
99 | - * |
|
100 | - * @param string $name name of the property |
|
101 | - * @param string $value String value of the property |
|
102 | - */ |
|
103 | - public function setProperty($name, $value) { |
|
104 | - if($value === null) { |
|
105 | - return; |
|
106 | - } |
|
88 | + /** |
|
89 | + * Set a property on this PropertySetter's Object. If successful, this |
|
90 | + * method will invoke a setter method on the underlying Object. The |
|
91 | + * setter is the one for the specified property name and the value is |
|
92 | + * determined partly from the setter argument type and partly from the |
|
93 | + * value specified in the call to this method. |
|
94 | + * |
|
95 | + * <p>If the setter expects a String no conversion is necessary. |
|
96 | + * If it expects an int, then an attempt is made to convert 'value' |
|
97 | + * to an int using new Integer(value). If the setter expects a boolean, |
|
98 | + * the conversion is by new Boolean(value). |
|
99 | + * |
|
100 | + * @param string $name name of the property |
|
101 | + * @param string $value String value of the property |
|
102 | + */ |
|
103 | + public function setProperty($name, $value) { |
|
104 | + if($value === null) { |
|
105 | + return; |
|
106 | + } |
|
107 | 107 | |
108 | - $method = "set" . ucfirst($name); |
|
108 | + $method = "set" . ucfirst($name); |
|
109 | 109 | |
110 | - if(!method_exists($this->obj, $method)) { |
|
111 | - throw new Exception("Error setting log4php property $name to $value: no method $method in class ".get_class($this->obj)."!"); |
|
112 | - } else { |
|
113 | - return call_user_func(array($this->obj, $method), $value); |
|
114 | - } |
|
115 | - } |
|
110 | + if(!method_exists($this->obj, $method)) { |
|
111 | + throw new Exception("Error setting log4php property $name to $value: no method $method in class ".get_class($this->obj)."!"); |
|
112 | + } else { |
|
113 | + return call_user_func(array($this->obj, $method), $value); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - public function activate() { |
|
118 | - if(method_exists($this->obj, 'activateoptions')) { |
|
119 | - return call_user_func(array($this->obj, 'activateoptions')); |
|
120 | - } |
|
121 | - } |
|
117 | + public function activate() { |
|
118 | + if(method_exists($this->obj, 'activateoptions')) { |
|
119 | + return call_user_func(array($this->obj, 'activateoptions')); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Creates an instances from the given class name. |
|
125 | - * |
|
126 | - * @param string $classname |
|
127 | - * @return an object from the class with the given classname |
|
128 | - */ |
|
129 | - public static function createObject($class) { |
|
130 | - if(!empty($class)) { |
|
131 | - $class = basename($class); |
|
132 | - return new $class(); |
|
133 | - } |
|
134 | - return null; |
|
135 | - } |
|
123 | + /** |
|
124 | + * Creates an instances from the given class name. |
|
125 | + * |
|
126 | + * @param string $classname |
|
127 | + * @return an object from the class with the given classname |
|
128 | + */ |
|
129 | + public static function createObject($class) { |
|
130 | + if(!empty($class)) { |
|
131 | + $class = basename($class); |
|
132 | + return new $class(); |
|
133 | + } |
|
134 | + return null; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
137 | + /** |
|
138 | 138 | * @param object $object |
139 | 139 | * @param string $name |
140 | 140 | * @param mixed $value |
@@ -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 | * @package log4php |
@@ -24,27 +24,27 @@ discard block |
||
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 | } |
@@ -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 | * Array for fast space padding |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * @subpackage helpers |
27 | 27 | */ |
28 | 28 | $GLOBALS['log4php.LoggerPatternConverter.spaces'] = array( |
29 | - " ", // 1 space |
|
30 | - " ", // 2 spaces |
|
31 | - " ", // 4 spaces |
|
32 | - " ", // 8 spaces |
|
33 | - " ", // 16 spaces |
|
34 | - " " ); // 32 spaces |
|
29 | + " ", // 1 space |
|
30 | + " ", // 2 spaces |
|
31 | + " ", // 4 spaces |
|
32 | + " ", // 8 spaces |
|
33 | + " ", // 16 spaces |
|
34 | + " " ); // 32 spaces |
|
35 | 35 | |
36 | 36 | |
37 | 37 | /** |
@@ -50,89 +50,89 @@ discard block |
||
50 | 50 | */ |
51 | 51 | class LoggerPatternConverter { |
52 | 52 | |
53 | - /** |
|
54 | - * @var LoggerPatternConverter next converter in converter chain |
|
55 | - */ |
|
56 | - public $next = null; |
|
53 | + /** |
|
54 | + * @var LoggerPatternConverter next converter in converter chain |
|
55 | + */ |
|
56 | + public $next = null; |
|
57 | 57 | |
58 | - public $min = -1; |
|
59 | - public $max = 0x7FFFFFFF; |
|
60 | - public $leftAlign = false; |
|
58 | + public $min = -1; |
|
59 | + public $max = 0x7FFFFFFF; |
|
60 | + public $leftAlign = false; |
|
61 | 61 | |
62 | - /** |
|
63 | - * Constructor |
|
64 | - * |
|
65 | - * @param LoggerFormattingInfo $fi |
|
66 | - */ |
|
67 | - public function __construct($fi = null) { |
|
68 | - if($fi !== null) { |
|
69 | - $this->min = $fi->min; |
|
70 | - $this->max = $fi->max; |
|
71 | - $this->leftAlign = $fi->leftAlign; |
|
72 | - } |
|
73 | - } |
|
62 | + /** |
|
63 | + * Constructor |
|
64 | + * |
|
65 | + * @param LoggerFormattingInfo $fi |
|
66 | + */ |
|
67 | + public function __construct($fi = null) { |
|
68 | + if($fi !== null) { |
|
69 | + $this->min = $fi->min; |
|
70 | + $this->max = $fi->max; |
|
71 | + $this->leftAlign = $fi->leftAlign; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Derived pattern converters must override this method in order to |
|
77 | - * convert conversion specifiers in the correct way. |
|
78 | - * |
|
79 | - * @param LoggerLoggingEvent $event |
|
80 | - */ |
|
81 | - public function convert($event) {} |
|
75 | + /** |
|
76 | + * Derived pattern converters must override this method in order to |
|
77 | + * convert conversion specifiers in the correct way. |
|
78 | + * |
|
79 | + * @param LoggerLoggingEvent $event |
|
80 | + */ |
|
81 | + public function convert($event) {} |
|
82 | 82 | |
83 | - /** |
|
84 | - * A template method for formatting in a converter specific way. |
|
85 | - * |
|
86 | - * @param string &$sbuf string buffer |
|
87 | - * @param LoggerLoggingEvent $e |
|
88 | - */ |
|
89 | - public function format(&$sbuf, $e) { |
|
90 | - $s = $this->convert($e); |
|
83 | + /** |
|
84 | + * A template method for formatting in a converter specific way. |
|
85 | + * |
|
86 | + * @param string &$sbuf string buffer |
|
87 | + * @param LoggerLoggingEvent $e |
|
88 | + */ |
|
89 | + public function format(&$sbuf, $e) { |
|
90 | + $s = $this->convert($e); |
|
91 | 91 | |
92 | - if($s == null or empty($s)) { |
|
93 | - if(0 < $this->min) { |
|
94 | - $this->spacePad($sbuf, $this->min); |
|
95 | - } |
|
96 | - return; |
|
97 | - } |
|
92 | + if($s == null or empty($s)) { |
|
93 | + if(0 < $this->min) { |
|
94 | + $this->spacePad($sbuf, $this->min); |
|
95 | + } |
|
96 | + return; |
|
97 | + } |
|
98 | 98 | |
99 | - $len = strlen($s); |
|
99 | + $len = strlen($s); |
|
100 | 100 | |
101 | - if($len > $this->max) { |
|
102 | - $sbuf .= substr($s , 0, ($len - $this->max)); |
|
103 | - } else if($len < $this->min) { |
|
104 | - if($this->leftAlign) { |
|
105 | - $sbuf .= $s; |
|
106 | - $this->spacePad($sbuf, ($this->min - $len)); |
|
107 | - } else { |
|
108 | - $this->spacePad($sbuf, ($this->min - $len)); |
|
109 | - $sbuf .= $s; |
|
110 | - } |
|
111 | - } else { |
|
112 | - $sbuf .= $s; |
|
113 | - } |
|
114 | - } |
|
101 | + if($len > $this->max) { |
|
102 | + $sbuf .= substr($s , 0, ($len - $this->max)); |
|
103 | + } else if($len < $this->min) { |
|
104 | + if($this->leftAlign) { |
|
105 | + $sbuf .= $s; |
|
106 | + $this->spacePad($sbuf, ($this->min - $len)); |
|
107 | + } else { |
|
108 | + $this->spacePad($sbuf, ($this->min - $len)); |
|
109 | + $sbuf .= $s; |
|
110 | + } |
|
111 | + } else { |
|
112 | + $sbuf .= $s; |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Fast space padding method. |
|
118 | - * |
|
119 | - * @param string $sbuf string buffer |
|
120 | - * @param integer $length pad length |
|
121 | - * |
|
122 | - * @todo reimplement using PHP string functions |
|
123 | - */ |
|
124 | - public function spacePad($sbuf, $length) { |
|
125 | - while($length >= 32) { |
|
126 | - $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][5]; |
|
127 | - $length -= 32; |
|
128 | - } |
|
116 | + /** |
|
117 | + * Fast space padding method. |
|
118 | + * |
|
119 | + * @param string $sbuf string buffer |
|
120 | + * @param integer $length pad length |
|
121 | + * |
|
122 | + * @todo reimplement using PHP string functions |
|
123 | + */ |
|
124 | + public function spacePad($sbuf, $length) { |
|
125 | + while($length >= 32) { |
|
126 | + $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][5]; |
|
127 | + $length -= 32; |
|
128 | + } |
|
129 | 129 | |
130 | - for($i = 4; $i >= 0; $i--) { |
|
131 | - if(($length & (1<<$i)) != 0) { |
|
132 | - $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][$i]; |
|
133 | - } |
|
134 | - } |
|
130 | + for($i = 4; $i >= 0; $i--) { |
|
131 | + if(($length & (1<<$i)) != 0) { |
|
132 | + $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][$i]; |
|
133 | + } |
|
134 | + } |
|
135 | 135 | |
136 | - // $sbuf = str_pad($sbuf, $length); |
|
137 | - } |
|
136 | + // $sbuf = str_pad($sbuf, $length); |
|
137 | + } |
|
138 | 138 | } |
@@ -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 | * @package log4php |
@@ -24,22 +24,22 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class LoggerClassNamePatternConverter extends LoggerNamedPatternConverter { |
26 | 26 | |
27 | - /** |
|
28 | - * Constructor |
|
29 | - * |
|
30 | - * @param string $formattingInfo |
|
31 | - * @param integer $precision |
|
32 | - */ |
|
33 | - public function __construct($formattingInfo, $precision) { |
|
34 | - parent::__construct($formattingInfo, $precision); |
|
35 | - } |
|
27 | + /** |
|
28 | + * Constructor |
|
29 | + * |
|
30 | + * @param string $formattingInfo |
|
31 | + * @param integer $precision |
|
32 | + */ |
|
33 | + public function __construct($formattingInfo, $precision) { |
|
34 | + parent::__construct($formattingInfo, $precision); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param LoggerLoggingEvent $event |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function getFullyQualifiedName($event) { |
|
42 | - return $event->fqcn; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @param LoggerLoggingEvent $event |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function getFullyQualifiedName($event) { |
|
42 | + return $event->fqcn; |
|
43 | + } |
|
44 | 44 | } |
45 | 45 |
@@ -24,30 +24,30 @@ |
||
24 | 24 | */ |
25 | 25 | class LoggerDatePatternConverter extends LoggerPatternConverter { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - private $df; |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + private $df; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor |
|
34 | - * |
|
35 | - * @param string $formattingInfo |
|
36 | - * @param string $df |
|
37 | - */ |
|
38 | - public function __construct($formattingInfo, $df) { |
|
39 | - parent::__construct($formattingInfo); |
|
40 | - $this->df = $df; |
|
41 | - } |
|
32 | + /** |
|
33 | + * Constructor |
|
34 | + * |
|
35 | + * @param string $formattingInfo |
|
36 | + * @param string $df |
|
37 | + */ |
|
38 | + public function __construct($formattingInfo, $df) { |
|
39 | + parent::__construct($formattingInfo); |
|
40 | + $this->df = $df; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param LoggerLoggingEvent $event |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function convert($event) { |
|
48 | - $timeStamp = $event->getTimeStamp(); |
|
49 | - $usecs = round(($timeStamp - (int)$timeStamp) * 1000); |
|
50 | - $this->df = preg_replace('/((?<!\\\\)(?:\\\\{2})*)u/', '${1}' . sprintf('%03d', $usecs), $this->df); |
|
51 | - return date($this->df, $event->getTimeStamp()); |
|
52 | - } |
|
43 | + /** |
|
44 | + * @param LoggerLoggingEvent $event |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function convert($event) { |
|
48 | + $timeStamp = $event->getTimeStamp(); |
|
49 | + $usecs = round(($timeStamp - (int)$timeStamp) * 1000); |
|
50 | + $this->df = preg_replace('/((?<!\\\\)(?:\\\\{2})*)u/', '${1}' . sprintf('%03d', $usecs), $this->df); |
|
51 | + return date($this->df, $event->getTimeStamp()); |
|
52 | + } |
|
53 | 53 | } |
@@ -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 | * Most of the work of the {@link LoggerPatternLayout} class |
@@ -33,309 +33,309 @@ discard block |
||
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,48 +24,48 @@ |
||
24 | 24 | */ |
25 | 25 | class LoggerBasicPatternConverter extends LoggerPatternConverter { |
26 | 26 | |
27 | - /** |
|
28 | - * @var integer |
|
29 | - */ |
|
30 | - private $type; |
|
27 | + /** |
|
28 | + * @var integer |
|
29 | + */ |
|
30 | + private $type; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor |
|
34 | - * |
|
35 | - * @param string $formattingInfo |
|
36 | - * @param integer $type |
|
37 | - */ |
|
38 | - public function __construct($formattingInfo, $type) { |
|
39 | - parent::__construct($formattingInfo); |
|
40 | - $this->type = $type; |
|
41 | - } |
|
32 | + /** |
|
33 | + * Constructor |
|
34 | + * |
|
35 | + * @param string $formattingInfo |
|
36 | + * @param integer $type |
|
37 | + */ |
|
38 | + public function __construct($formattingInfo, $type) { |
|
39 | + parent::__construct($formattingInfo); |
|
40 | + $this->type = $type; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param LoggerLoggingEvent $event |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function convert($event) { |
|
48 | - switch($this->type) { |
|
49 | - case LoggerPatternParser::RELATIVE_TIME_CONVERTER: |
|
50 | - $timeStamp = $event->getTimeStamp(); |
|
51 | - $startTime = LoggerLoggingEvent::getStartTime(); |
|
52 | - return (string)(int)($timeStamp * 1000 - $startTime * 1000); |
|
43 | + /** |
|
44 | + * @param LoggerLoggingEvent $event |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function convert($event) { |
|
48 | + switch($this->type) { |
|
49 | + case LoggerPatternParser::RELATIVE_TIME_CONVERTER: |
|
50 | + $timeStamp = $event->getTimeStamp(); |
|
51 | + $startTime = LoggerLoggingEvent::getStartTime(); |
|
52 | + return (string)(int)($timeStamp * 1000 - $startTime * 1000); |
|
53 | 53 | |
54 | - case LoggerPatternParser::THREAD_CONVERTER: |
|
55 | - return $event->getThreadName(); |
|
54 | + case LoggerPatternParser::THREAD_CONVERTER: |
|
55 | + return $event->getThreadName(); |
|
56 | 56 | |
57 | - case LoggerPatternParser::LEVEL_CONVERTER: |
|
58 | - $level = $event->getLevel(); |
|
59 | - return $level->toString(); |
|
57 | + case LoggerPatternParser::LEVEL_CONVERTER: |
|
58 | + $level = $event->getLevel(); |
|
59 | + return $level->toString(); |
|
60 | 60 | |
61 | - case LoggerPatternParser::NDC_CONVERTER: |
|
62 | - return $event->getNDC(); |
|
61 | + case LoggerPatternParser::NDC_CONVERTER: |
|
62 | + return $event->getNDC(); |
|
63 | 63 | |
64 | - case LoggerPatternParser::MESSAGE_CONVERTER: |
|
65 | - return $event->getRenderedMessage(); |
|
64 | + case LoggerPatternParser::MESSAGE_CONVERTER: |
|
65 | + return $event->getRenderedMessage(); |
|
66 | 66 | |
67 | - default: |
|
68 | - return ''; |
|
69 | - } |
|
70 | - } |
|
67 | + default: |
|
68 | + return ''; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | } |
@@ -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 class encapsulates the information obtained when parsing |
@@ -28,23 +28,23 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class LoggerFormattingInfo { |
30 | 30 | |
31 | - public $min = -1; |
|
32 | - public $max = 0x7FFFFFFF; |
|
33 | - public $leftAlign = false; |
|
31 | + public $min = -1; |
|
32 | + public $max = 0x7FFFFFFF; |
|
33 | + public $leftAlign = false; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor |
|
37 | - */ |
|
38 | - public function __construct() {} |
|
35 | + /** |
|
36 | + * Constructor |
|
37 | + */ |
|
38 | + public function __construct() {} |
|
39 | 39 | |
40 | - public function reset() { |
|
41 | - $this->min = -1; |
|
42 | - $this->max = 0x7FFFFFFF; |
|
43 | - $this->leftAlign = false; |
|
44 | - } |
|
40 | + public function reset() { |
|
41 | + $this->min = -1; |
|
42 | + $this->max = 0x7FFFFFFF; |
|
43 | + $this->leftAlign = false; |
|
44 | + } |
|
45 | 45 | |
46 | - public function dump() { |
|
47 | - // TODO: other option to dump? |
|
48 | - // LoggerLog::debug("LoggerFormattingInfo::dump() min={$this->min}, max={$this->max}, leftAlign={$this->leftAlign}"); |
|
49 | - } |
|
46 | + public function dump() { |
|
47 | + // TODO: other option to dump? |
|
48 | + // LoggerLog::debug("LoggerFormattingInfo::dump() min={$this->min}, max={$this->max}, leftAlign={$this->leftAlign}"); |
|
49 | + } |
|
50 | 50 | } |
@@ -24,40 +24,40 @@ |
||
24 | 24 | */ |
25 | 25 | class LoggerLocationPatternConverter extends LoggerPatternConverter { |
26 | 26 | |
27 | - /** |
|
28 | - * @var integer |
|
29 | - */ |
|
30 | - private $type; |
|
27 | + /** |
|
28 | + * @var integer |
|
29 | + */ |
|
30 | + private $type; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor |
|
34 | - * |
|
35 | - * @param string $formattingInfo |
|
36 | - * @param integer $type |
|
37 | - */ |
|
38 | - public function __construct($formattingInfo, $type) { |
|
39 | - parent::__construct($formattingInfo); |
|
40 | - $this->type = $type; |
|
41 | - } |
|
32 | + /** |
|
33 | + * Constructor |
|
34 | + * |
|
35 | + * @param string $formattingInfo |
|
36 | + * @param integer $type |
|
37 | + */ |
|
38 | + public function __construct($formattingInfo, $type) { |
|
39 | + parent::__construct($formattingInfo); |
|
40 | + $this->type = $type; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param LoggerLoggingEvent $event |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function convert($event) { |
|
48 | - $locationInfo = $event->getLocationInformation(); |
|
49 | - switch($this->type) { |
|
50 | - case LoggerPatternParser::FULL_LOCATION_CONVERTER: |
|
51 | - return $locationInfo->getFullInfo(); |
|
52 | - case LoggerPatternParser::METHOD_LOCATION_CONVERTER: |
|
53 | - return $locationInfo->getMethodName(); |
|
54 | - case LoggerPatternParser::LINE_LOCATION_CONVERTER: |
|
55 | - return $locationInfo->getLineNumber(); |
|
56 | - case LoggerPatternParser::FILE_LOCATION_CONVERTER: |
|
57 | - return $locationInfo->getFileName(); |
|
58 | - default: |
|
59 | - return ''; |
|
60 | - } |
|
61 | - } |
|
43 | + /** |
|
44 | + * @param LoggerLoggingEvent $event |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function convert($event) { |
|
48 | + $locationInfo = $event->getLocationInformation(); |
|
49 | + switch($this->type) { |
|
50 | + case LoggerPatternParser::FULL_LOCATION_CONVERTER: |
|
51 | + return $locationInfo->getFullInfo(); |
|
52 | + case LoggerPatternParser::METHOD_LOCATION_CONVERTER: |
|
53 | + return $locationInfo->getMethodName(); |
|
54 | + case LoggerPatternParser::LINE_LOCATION_CONVERTER: |
|
55 | + return $locationInfo->getLineNumber(); |
|
56 | + case LoggerPatternParser::FILE_LOCATION_CONVERTER: |
|
57 | + return $locationInfo->getFileName(); |
|
58 | + default: |
|
59 | + return ''; |
|
60 | + } |
|
61 | + } |
|
62 | 62 | } |
63 | 63 |