@@ -180,6 +180,7 @@ discard block |
||
180 | 180 | * @access private |
181 | 181 | * @param string Login |
182 | 182 | * @param integer Key |
183 | + * @param integer $key |
|
183 | 184 | * @return string |
184 | 185 | */ |
185 | 186 | function _xor($login, $key) |
@@ -208,6 +209,7 @@ discard block |
||
208 | 209 | * @access private |
209 | 210 | * @param string Login |
210 | 211 | * @param integer Key |
212 | + * @param integer $key |
|
211 | 213 | * @return string |
212 | 214 | */ |
213 | 215 | function _rotx($login, $key) |
@@ -241,6 +243,7 @@ discard block |
||
241 | 243 | * @access private |
242 | 244 | * @param string Login |
243 | 245 | * @param integer Key |
246 | + * @param integer $key |
|
244 | 247 | * @return string |
245 | 248 | */ |
246 | 249 | function _rotxpp($login, $key) |
@@ -274,6 +277,7 @@ discard block |
||
274 | 277 | * @access private |
275 | 278 | * @param string Login |
276 | 279 | * @param integer Key |
280 | + * @param integer $key |
|
277 | 281 | * @return string |
278 | 282 | */ |
279 | 283 | function _rotxmm($login, $key) |
@@ -306,6 +310,7 @@ discard block |
||
306 | 310 | * @access private |
307 | 311 | * @param string Login |
308 | 312 | * @param integer Key |
313 | + * @param integer $key |
|
309 | 314 | * @return string |
310 | 315 | */ |
311 | 316 | function _asciiRotx($login, $key) |
@@ -340,6 +345,7 @@ discard block |
||
340 | 345 | * @access private |
341 | 346 | * @param string Login |
342 | 347 | * @param integer Key |
348 | + * @param integer $key |
|
343 | 349 | * @return string |
344 | 350 | */ |
345 | 351 | function _asciiRotxpp($login, $key) |
@@ -374,6 +380,7 @@ discard block |
||
374 | 380 | * @access private |
375 | 381 | * @param string Login |
376 | 382 | * @param integer Key |
383 | + * @param integer $key |
|
377 | 384 | * @return string |
378 | 385 | */ |
379 | 386 | function _asciiRotxmm($login, $key) |
@@ -430,6 +437,7 @@ discard block |
||
430 | 437 | * |
431 | 438 | * @access private |
432 | 439 | * @param integer Length of the password |
440 | + * @param integer $length |
|
433 | 441 | * @return string Returns the password |
434 | 442 | */ |
435 | 443 | function _createPronounceable($length) |
@@ -475,6 +483,8 @@ discard block |
||
475 | 483 | * @param string Character which could be use in the |
476 | 484 | * unpronounceable password ex : 'ABCDEFG' |
477 | 485 | * or numeric, alphabetical or alphanumeric. |
486 | + * @param integer $length |
|
487 | + * @param string $chars |
|
478 | 488 | * @return string Returns the password |
479 | 489 | */ |
480 | 490 | function _createUnpronounceable($length, $chars) |
@@ -441,17 +441,17 @@ discard block |
||
441 | 441 | * List of vowels and vowel sounds |
442 | 442 | */ |
443 | 443 | $v = array('a', 'e', 'i', 'o', 'u', 'ae', 'ou', 'io', |
444 | - 'ea', 'ou', 'ia', 'ai' |
|
445 | - ); |
|
444 | + 'ea', 'ou', 'ia', 'ai' |
|
445 | + ); |
|
446 | 446 | |
447 | 447 | /** |
448 | 448 | * List of consonants and consonant sounds |
449 | 449 | */ |
450 | 450 | $c = array('b', 'c', 'd', 'g', 'h', 'j', 'k', 'l', 'm', |
451 | - 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', |
|
452 | - 'tr', 'cr', 'fr', 'dr', 'wr', 'pr', 'th', |
|
453 | - 'ch', 'ph', 'st', 'sl', 'cl' |
|
454 | - ); |
|
451 | + 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', |
|
452 | + 'tr', 'cr', 'fr', 'dr', 'wr', 'pr', 'th', |
|
453 | + 'ch', 'ph', 'st', 'sl', 'cl' |
|
454 | + ); |
|
455 | 455 | |
456 | 456 | $v_count = 12; |
457 | 457 | $c_count = 29; |
@@ -484,50 +484,50 @@ discard block |
||
484 | 484 | /** |
485 | 485 | * List of character which could be use in the password |
486 | 486 | */ |
487 | - switch($chars) { |
|
487 | + switch($chars) { |
|
488 | 488 | |
489 | - case 'alphanumeric': |
|
489 | + case 'alphanumeric': |
|
490 | 490 | $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
491 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 62; |
|
492 | - break; |
|
491 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 62; |
|
492 | + break; |
|
493 | 493 | |
494 | - case 'alphabetical': |
|
494 | + case 'alphabetical': |
|
495 | 495 | $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
496 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 52; |
|
497 | - break; |
|
496 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 52; |
|
497 | + break; |
|
498 | 498 | |
499 | - case 'numeric': |
|
499 | + case 'numeric': |
|
500 | 500 | $chars = '0123456789'; |
501 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 10; |
|
502 | - break; |
|
501 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 10; |
|
502 | + break; |
|
503 | 503 | |
504 | - case '': |
|
504 | + case '': |
|
505 | 505 | $chars = '_#@%&ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
506 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 67; |
|
507 | - break; |
|
506 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 67; |
|
507 | + break; |
|
508 | 508 | |
509 | - default: |
|
509 | + default: |
|
510 | 510 | /** |
511 | 511 | * Some characters shouldn't be used |
512 | 512 | */ |
513 | 513 | $chars = trim($chars); |
514 | - $chars = str_replace(array('+', '|', '$', '^', '/', '\\', ','), '', $chars); |
|
515 | - |
|
516 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = strlen($chars); |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Generate password |
|
521 | - */ |
|
522 | - for ($i = 0; $i < $length; $i++) { |
|
523 | - $num = mt_rand(0, $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] - 1); |
|
524 | - $password .= $chars{$num}; |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Return password |
|
529 | - */ |
|
530 | - return $password; |
|
514 | + $chars = str_replace(array('+', '|', '$', '^', '/', '\\', ','), '', $chars); |
|
515 | + |
|
516 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = strlen($chars); |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Generate password |
|
521 | + */ |
|
522 | + for ($i = 0; $i < $length; $i++) { |
|
523 | + $num = mt_rand(0, $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] - 1); |
|
524 | + $password .= $chars{$num}; |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Return password |
|
529 | + */ |
|
530 | + return $password; |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | ?> |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | function create($length = 10, $type = 'pronounceable', $chars = '') |
56 | 56 | { |
57 | 57 | switch ($type) { |
58 | - case 'unpronounceable' : |
|
59 | - return Text_Password::_createUnpronounceable($length, $chars); |
|
58 | + case 'unpronounceable' : |
|
59 | + return Text_Password::_createUnpronounceable($length, $chars); |
|
60 | 60 | |
61 | - case 'pronounceable' : |
|
62 | - default : |
|
63 | - return Text_Password::_createPronounceable($length); |
|
61 | + case 'pronounceable' : |
|
62 | + default : |
|
63 | + return Text_Password::_createPronounceable($length); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
@@ -110,35 +110,35 @@ discard block |
||
110 | 110 | function createFromLogin($login, $type, $key = 0) |
111 | 111 | { |
112 | 112 | switch ($type) { |
113 | - case 'reverse': |
|
114 | - return strrev($login); |
|
113 | + case 'reverse': |
|
114 | + return strrev($login); |
|
115 | 115 | |
116 | - case 'shuffle': |
|
117 | - return Text_Password::_shuffle($login); |
|
116 | + case 'shuffle': |
|
117 | + return Text_Password::_shuffle($login); |
|
118 | 118 | |
119 | - case 'xor': |
|
120 | - return Text_Password::_xor($login, $key); |
|
119 | + case 'xor': |
|
120 | + return Text_Password::_xor($login, $key); |
|
121 | 121 | |
122 | - case 'rot13': |
|
123 | - return str_rot13($login); |
|
122 | + case 'rot13': |
|
123 | + return str_rot13($login); |
|
124 | 124 | |
125 | - case 'rotx': |
|
126 | - return Text_Password::_rotx($login, $key); |
|
125 | + case 'rotx': |
|
126 | + return Text_Password::_rotx($login, $key); |
|
127 | 127 | |
128 | - case 'rotx++': |
|
129 | - return Text_Password::_rotxpp($login, $key); |
|
128 | + case 'rotx++': |
|
129 | + return Text_Password::_rotxpp($login, $key); |
|
130 | 130 | |
131 | - case 'rotx--': |
|
132 | - return Text_Password::_rotxmm($login, $key); |
|
131 | + case 'rotx--': |
|
132 | + return Text_Password::_rotxmm($login, $key); |
|
133 | 133 | |
134 | - case 'ascii_rotx': |
|
135 | - return Text_Password::_asciiRotx($login, $key); |
|
134 | + case 'ascii_rotx': |
|
135 | + return Text_Password::_asciiRotx($login, $key); |
|
136 | 136 | |
137 | - case 'ascii_rotx++': |
|
138 | - return Text_Password::_asciiRotxpp($login, $key); |
|
137 | + case 'ascii_rotx++': |
|
138 | + return Text_Password::_asciiRotxpp($login, $key); |
|
139 | 139 | |
140 | - case 'ascii_rotx--': |
|
141 | - return Text_Password::_asciiRotxmm($login, $key); |
|
140 | + case 'ascii_rotx--': |
|
141 | + return Text_Password::_asciiRotxmm($login, $key); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
@@ -320,11 +320,11 @@ discard block |
||
320 | 320 | $next += 255; |
321 | 321 | } |
322 | 322 | switch ($next) { // delete white space |
323 | - case 0x09: |
|
324 | - case 0x20: |
|
325 | - case 0x0A: |
|
326 | - case 0x0D: |
|
327 | - $next++; |
|
323 | + case 0x09: |
|
324 | + case 0x20: |
|
325 | + case 0x0A: |
|
326 | + case 0x0D: |
|
327 | + $next++; |
|
328 | 328 | } |
329 | 329 | $tmp .= chr($next); |
330 | 330 | } |
@@ -354,11 +354,11 @@ discard block |
||
354 | 354 | $next += 255; |
355 | 355 | } |
356 | 356 | switch ($next) { // delete white space |
357 | - case 0x09: |
|
358 | - case 0x20: |
|
359 | - case 0x0A: |
|
360 | - case 0x0D: |
|
361 | - $next++; |
|
357 | + case 0x09: |
|
358 | + case 0x20: |
|
359 | + case 0x0A: |
|
360 | + case 0x0D: |
|
361 | + $next++; |
|
362 | 362 | } |
363 | 363 | $tmp .= chr($next); |
364 | 364 | } |
@@ -388,11 +388,11 @@ discard block |
||
388 | 388 | $next += 255; |
389 | 389 | } |
390 | 390 | switch ($next) { // delete white space |
391 | - case 0x09: |
|
392 | - case 0x20: |
|
393 | - case 0x0A: |
|
394 | - case 0x0D: |
|
395 | - $next++; |
|
391 | + case 0x09: |
|
392 | + case 0x20: |
|
393 | + case 0x0A: |
|
394 | + case 0x0D: |
|
395 | + $next++; |
|
396 | 396 | } |
397 | 397 | $tmp .= chr($next); |
398 | 398 | } |
@@ -486,34 +486,34 @@ discard block |
||
486 | 486 | */ |
487 | 487 | switch($chars) { |
488 | 488 | |
489 | - case 'alphanumeric': |
|
490 | - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
491 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 62; |
|
492 | - break; |
|
489 | + case 'alphanumeric': |
|
490 | + $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
491 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 62; |
|
492 | + break; |
|
493 | 493 | |
494 | - case 'alphabetical': |
|
495 | - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
|
496 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 52; |
|
497 | - break; |
|
494 | + case 'alphabetical': |
|
495 | + $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
|
496 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 52; |
|
497 | + break; |
|
498 | 498 | |
499 | - case 'numeric': |
|
500 | - $chars = '0123456789'; |
|
501 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 10; |
|
502 | - break; |
|
499 | + case 'numeric': |
|
500 | + $chars = '0123456789'; |
|
501 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 10; |
|
502 | + break; |
|
503 | 503 | |
504 | - case '': |
|
505 | - $chars = '_#@%&ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
506 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 67; |
|
507 | - break; |
|
504 | + case '': |
|
505 | + $chars = '_#@%&ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
506 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = 67; |
|
507 | + break; |
|
508 | 508 | |
509 | - default: |
|
510 | - /** |
|
509 | + default: |
|
510 | + /** |
|
511 | 511 | * Some characters shouldn't be used |
512 | 512 | */ |
513 | - $chars = trim($chars); |
|
514 | - $chars = str_replace(array('+', '|', '$', '^', '/', '\\', ','), '', $chars); |
|
513 | + $chars = trim($chars); |
|
514 | + $chars = str_replace(array('+', '|', '$', '^', '/', '\\', ','), '', $chars); |
|
515 | 515 | |
516 | - $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = strlen($chars); |
|
516 | + $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = strlen($chars); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | $GLOBALS['_Text_Password_NumberOfPossibleCharacters'] = $v_count + $c_count; |
460 | 460 | |
461 | 461 | for ($i = 0; $i < $length; $i++) { |
462 | - $retVal .= $c[mt_rand(0, $c_count-1)] . $v[mt_rand(0, $v_count-1)]; |
|
462 | + $retVal .= $c[mt_rand(0, $c_count - 1)].$v[mt_rand(0, $v_count - 1)]; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | return substr($retVal, 0, $length); |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | /** |
485 | 485 | * List of character which could be use in the password |
486 | 486 | */ |
487 | - switch($chars) { |
|
487 | + switch ($chars) { |
|
488 | 488 | |
489 | 489 | case 'alphanumeric': |
490 | 490 | $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
@@ -115,7 +115,7 @@ |
||
115 | 115 | * Setup db connection. |
116 | 116 | * Based on defined options, this method connects to db defined in {@link $dsn} |
117 | 117 | * and creates a {@link $table} table if {@link $createTable} is true. |
118 | - * @return boolean true if all ok. |
|
118 | + * @return boolean|null true if all ok. |
|
119 | 119 | */ |
120 | 120 | function activateOptions() |
121 | 121 | { |
@@ -121,10 +121,10 @@ |
||
121 | 121 | { |
122 | 122 | $this->db = &ADONewConnection($this->type); |
123 | 123 | if (! $this->db->PConnect($this->host, $this->user, $this->password, $this->database)) { |
124 | - $this->db = null; |
|
125 | - $this->closed = true; |
|
126 | - $this->canAppend = false; |
|
127 | - return; |
|
124 | + $this->db = null; |
|
125 | + $this->closed = true; |
|
126 | + $this->canAppend = false; |
|
127 | + return; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | $this->layout = LoggerReflectionUtils::createObject('LoggerLayoutPattern'); |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | |
21 | 21 | /** A docblok to make phpdoc happy */ |
22 | -require_once(ADODB_DIR . '/adodb.inc.php'); |
|
22 | +require_once(ADODB_DIR.'/adodb.inc.php'); |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Appends log events to a db table using adodb class. |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | function activateOptions() |
121 | 121 | { |
122 | 122 | $this->db = &ADONewConnection($this->type); |
123 | - if (! $this->db->PConnect($this->host, $this->user, $this->password, $this->database)) { |
|
123 | + if (!$this->db->PConnect($this->host, $this->user, $this->password, $this->database)) { |
|
124 | 124 | $this->db = null; |
125 | 125 | $this->closed = true; |
126 | 126 | $this->canAppend = false; |
@@ -131,14 +131,14 @@ discard block |
||
131 | 131 | $this->layout->setConversionPattern($this->getSql()); |
132 | 132 | |
133 | 133 | // test if log table exists |
134 | - $sql = 'select * from ' . $this->table . ' where 1 = 0'; |
|
134 | + $sql = 'select * from '.$this->table.' where 1 = 0'; |
|
135 | 135 | $dbrs = $this->db->Execute($sql); |
136 | 136 | if ($dbrs == false and $this->getCreateTable()) { |
137 | 137 | $query = "CREATE TABLE {$this->table} (timestamp varchar(32),logger varchar(32),level varchar(32),message varchar(64),thread varchar(32),file varchar(64),line varchar(4) );"; |
138 | 138 | |
139 | 139 | |
140 | 140 | $result = $this->db->Execute($query); |
141 | - if (! $result) { |
|
141 | + if (!$result) { |
|
142 | 142 | $this->canAppend = false; |
143 | 143 | return; |
144 | 144 | } |
@@ -155,8 +155,9 @@ |
||
155 | 155 | |
156 | 156 | function close() |
157 | 157 | { |
158 | - if ($this->db !== null) |
|
159 | - $this->db->Close(); |
|
158 | + if ($this->db !== null) { |
|
159 | + $this->db->Close(); |
|
160 | + } |
|
160 | 161 | $this->closed = true; |
161 | 162 | } |
162 | 163 |
@@ -151,10 +151,16 @@ |
||
151 | 151 | return $this->append; |
152 | 152 | } |
153 | 153 | |
154 | + /** |
|
155 | + * @param boolean $flag |
|
156 | + */ |
|
154 | 157 | public function setAppend($flag) { |
155 | 158 | $this->append = LoggerOptionConverter::toBoolean($flag, true); |
156 | 159 | } |
157 | 160 | |
161 | + /** |
|
162 | + * @param string $fileName |
|
163 | + */ |
|
158 | 164 | public function setFileName($fileName) { |
159 | 165 | $this->fileName = $fileName; |
160 | 166 | } |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | public function activateOptions() { |
68 | 68 | $fileName = $this->getFile(); |
69 | 69 | |
70 | - if(!is_file($fileName)) { |
|
70 | + if (!is_file($fileName)) { |
|
71 | 71 | $dir = dirname($fileName); |
72 | - if(!is_dir($dir)) { |
|
72 | + if (!is_dir($dir)) { |
|
73 | 73 | mkdir($dir, 0777, true); |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
78 | - if($this->fp) { |
|
79 | - if(flock($this->fp, LOCK_EX)) { |
|
80 | - if($this->getAppend()) { |
|
77 | + $this->fp = fopen($fileName, ($this->getAppend() ? 'a' : 'w')); |
|
78 | + if ($this->fp) { |
|
79 | + if (flock($this->fp, LOCK_EX)) { |
|
80 | + if ($this->getAppend()) { |
|
81 | 81 | fseek($this->fp, 0, SEEK_END); |
82 | 82 | } |
83 | 83 | fwrite($this->fp, $this->layout->getHeader()); |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | public function close() { |
96 | - if($this->closed != true) { |
|
97 | - if($this->fp and $this->layout !== null) { |
|
98 | - if(flock($this->fp, LOCK_EX)) { |
|
96 | + if ($this->closed != true) { |
|
97 | + if ($this->fp and $this->layout !== null) { |
|
98 | + if (flock($this->fp, LOCK_EX)) { |
|
99 | 99 | fwrite($this->fp, $this->layout->getFooter()); |
100 | 100 | flock($this->fp, LOCK_UN); |
101 | 101 | } |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | public function append(LoggerLoggingEvent $event) { |
109 | - if($this->fp and $this->layout !== null) { |
|
110 | - if(flock($this->fp, LOCK_EX)) { |
|
109 | + if ($this->fp and $this->layout !== null) { |
|
110 | + if (flock($this->fp, LOCK_EX)) { |
|
111 | 111 | fwrite($this->fp, $this->layout->format($event)); |
112 | 112 | flock($this->fp, LOCK_UN); |
113 | 113 | } else { |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function setFile() { |
129 | 129 | $numargs = func_num_args(); |
130 | - $args = func_get_args(); |
|
130 | + $args = func_get_args(); |
|
131 | 131 | |
132 | - if($numargs == 1 and is_string($args[0])) { |
|
132 | + if ($numargs == 1 and is_string($args[0])) { |
|
133 | 133 | $this->setFileName($args[0]); |
134 | - } else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { |
|
134 | + } else if ($numargs >= 2 and is_string($args[0]) and is_bool($args[1])) { |
|
135 | 135 | $this->setFile($args[0]); |
136 | 136 | $this->setAppend($args[1]); |
137 | 137 | } |
@@ -42,129 +42,129 @@ |
||
42 | 42 | */ |
43 | 43 | class LoggerAppenderFile extends LoggerAppender { |
44 | 44 | |
45 | - /** |
|
46 | - * @var boolean if {@link $file} exists, appends events. |
|
47 | - */ |
|
48 | - private $append = true; |
|
49 | - /** |
|
50 | - * @var string the file name used to append events |
|
51 | - */ |
|
52 | - protected $fileName; |
|
53 | - /** |
|
54 | - * @var mixed file resource |
|
55 | - */ |
|
56 | - protected $fp = false; |
|
45 | + /** |
|
46 | + * @var boolean if {@link $file} exists, appends events. |
|
47 | + */ |
|
48 | + private $append = true; |
|
49 | + /** |
|
50 | + * @var string the file name used to append events |
|
51 | + */ |
|
52 | + protected $fileName; |
|
53 | + /** |
|
54 | + * @var mixed file resource |
|
55 | + */ |
|
56 | + protected $fp = false; |
|
57 | 57 | |
58 | - public function __construct($name = '') { |
|
59 | - parent::__construct($name); |
|
60 | - $this->requiresLayout = true; |
|
61 | - } |
|
58 | + public function __construct($name = '') { |
|
59 | + parent::__construct($name); |
|
60 | + $this->requiresLayout = true; |
|
61 | + } |
|
62 | 62 | |
63 | - public function __destruct() { |
|
64 | - $this->close(); |
|
65 | - } |
|
63 | + public function __destruct() { |
|
64 | + $this->close(); |
|
65 | + } |
|
66 | 66 | |
67 | - public function activateOptions() { |
|
68 | - $fileName = $this->getFile(); |
|
67 | + public function activateOptions() { |
|
68 | + $fileName = $this->getFile(); |
|
69 | 69 | |
70 | - if(!is_file($fileName)) { |
|
71 | - $dir = dirname($fileName); |
|
72 | - if(!is_dir($dir)) { |
|
73 | - mkdir($dir, 0777, true); |
|
74 | - } |
|
75 | - } |
|
70 | + if(!is_file($fileName)) { |
|
71 | + $dir = dirname($fileName); |
|
72 | + if(!is_dir($dir)) { |
|
73 | + mkdir($dir, 0777, true); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
78 | - if($this->fp) { |
|
79 | - if(flock($this->fp, LOCK_EX)) { |
|
80 | - if($this->getAppend()) { |
|
81 | - fseek($this->fp, 0, SEEK_END); |
|
82 | - } |
|
83 | - fwrite($this->fp, $this->layout->getHeader()); |
|
84 | - flock($this->fp, LOCK_UN); |
|
85 | - $this->closed = false; |
|
86 | - } else { |
|
87 | - // TODO: should we take some action in this case? |
|
88 | - $this->closed = true; |
|
89 | - } |
|
90 | - } else { |
|
91 | - $this->closed = true; |
|
92 | - } |
|
93 | - } |
|
77 | + $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
78 | + if($this->fp) { |
|
79 | + if(flock($this->fp, LOCK_EX)) { |
|
80 | + if($this->getAppend()) { |
|
81 | + fseek($this->fp, 0, SEEK_END); |
|
82 | + } |
|
83 | + fwrite($this->fp, $this->layout->getHeader()); |
|
84 | + flock($this->fp, LOCK_UN); |
|
85 | + $this->closed = false; |
|
86 | + } else { |
|
87 | + // TODO: should we take some action in this case? |
|
88 | + $this->closed = true; |
|
89 | + } |
|
90 | + } else { |
|
91 | + $this->closed = true; |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - public function close() { |
|
96 | - if($this->closed != true) { |
|
97 | - if($this->fp and $this->layout !== null) { |
|
98 | - if(flock($this->fp, LOCK_EX)) { |
|
99 | - fwrite($this->fp, $this->layout->getFooter()); |
|
100 | - flock($this->fp, LOCK_UN); |
|
101 | - } |
|
102 | - fclose($this->fp); |
|
103 | - } |
|
104 | - $this->closed = true; |
|
105 | - } |
|
106 | - } |
|
95 | + public function close() { |
|
96 | + if($this->closed != true) { |
|
97 | + if($this->fp and $this->layout !== null) { |
|
98 | + if(flock($this->fp, LOCK_EX)) { |
|
99 | + fwrite($this->fp, $this->layout->getFooter()); |
|
100 | + flock($this->fp, LOCK_UN); |
|
101 | + } |
|
102 | + fclose($this->fp); |
|
103 | + } |
|
104 | + $this->closed = true; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - public function append(LoggerLoggingEvent $event) { |
|
109 | - if($this->fp and $this->layout !== null) { |
|
110 | - if(flock($this->fp, LOCK_EX)) { |
|
111 | - fwrite($this->fp, $this->layout->format($event)); |
|
112 | - flock($this->fp, LOCK_UN); |
|
113 | - } else { |
|
114 | - $this->closed = true; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
108 | + public function append(LoggerLoggingEvent $event) { |
|
109 | + if($this->fp and $this->layout !== null) { |
|
110 | + if(flock($this->fp, LOCK_EX)) { |
|
111 | + fwrite($this->fp, $this->layout->format($event)); |
|
112 | + flock($this->fp, LOCK_UN); |
|
113 | + } else { |
|
114 | + $this->closed = true; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Sets and opens the file where the log output will go. |
|
121 | - * |
|
122 | - * This is an overloaded method. It can be called with: |
|
123 | - * - setFile(string $fileName) to set filename. |
|
124 | - * - setFile(string $fileName, boolean $append) to set filename and append. |
|
125 | - * |
|
126 | - * TODO: remove overloading. Use only file as alias to filename |
|
127 | - */ |
|
128 | - public function setFile() { |
|
129 | - $numargs = func_num_args(); |
|
130 | - $args = func_get_args(); |
|
119 | + /** |
|
120 | + * Sets and opens the file where the log output will go. |
|
121 | + * |
|
122 | + * This is an overloaded method. It can be called with: |
|
123 | + * - setFile(string $fileName) to set filename. |
|
124 | + * - setFile(string $fileName, boolean $append) to set filename and append. |
|
125 | + * |
|
126 | + * TODO: remove overloading. Use only file as alias to filename |
|
127 | + */ |
|
128 | + public function setFile() { |
|
129 | + $numargs = func_num_args(); |
|
130 | + $args = func_get_args(); |
|
131 | 131 | |
132 | - if($numargs == 1 and is_string($args[0])) { |
|
133 | - $this->setFileName($args[0]); |
|
134 | - } else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { |
|
135 | - $this->setFile($args[0]); |
|
136 | - $this->setAppend($args[1]); |
|
137 | - } |
|
138 | - } |
|
132 | + if($numargs == 1 and is_string($args[0])) { |
|
133 | + $this->setFileName($args[0]); |
|
134 | + } else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { |
|
135 | + $this->setFile($args[0]); |
|
136 | + $this->setAppend($args[1]); |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function getFile() { |
|
144 | - return $this->getFileName(); |
|
145 | - } |
|
140 | + /** |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function getFile() { |
|
144 | + return $this->getFileName(); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @return boolean |
|
149 | - */ |
|
150 | - public function getAppend() { |
|
151 | - return $this->append; |
|
152 | - } |
|
147 | + /** |
|
148 | + * @return boolean |
|
149 | + */ |
|
150 | + public function getAppend() { |
|
151 | + return $this->append; |
|
152 | + } |
|
153 | 153 | |
154 | - public function setAppend($flag) { |
|
155 | - $this->append = LoggerOptionConverter::toBoolean($flag, true); |
|
156 | - } |
|
154 | + public function setAppend($flag) { |
|
155 | + $this->append = LoggerOptionConverter::toBoolean($flag, true); |
|
156 | + } |
|
157 | 157 | |
158 | - public function setFileName($fileName) { |
|
159 | - $this->fileName = $fileName; |
|
160 | - } |
|
158 | + public function setFileName($fileName) { |
|
159 | + $this->fileName = $fileName; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function getFileName() { |
|
166 | - return $this->fileName; |
|
167 | - } |
|
162 | + /** |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function getFileName() { |
|
166 | + return $this->fileName; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | |
170 | 170 | } |
@@ -92,7 +92,7 @@ |
||
92 | 92 | |
93 | 93 | /** |
94 | 94 | * Returns the value of the MaxBackupIndex option. |
95 | - * @return integer |
|
95 | + * @return string |
|
96 | 96 | */ |
97 | 97 | private function getExpandedFileName() { |
98 | 98 | return $this->expandedFileName; |
@@ -48,183 +48,183 @@ |
||
48 | 48 | */ |
49 | 49 | class LoggerAppenderRollingFile extends LoggerAppenderFile { |
50 | 50 | |
51 | - /** |
|
52 | - * Set the maximum size that the output file is allowed to reach |
|
53 | - * before being rolled over to backup files. |
|
54 | - * |
|
55 | - * <p>In configuration files, the <var>MaxFileSize</var> option takes a |
|
56 | - * long integer in the range 0 - 2^63. You can specify the value |
|
57 | - * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
58 | - * interpreted being expressed respectively in kilobytes, megabytes |
|
59 | - * or gigabytes. For example, the value "10KB" will be interpreted |
|
60 | - * as 10240.</p> |
|
61 | - * <p>The default maximum file size is 10MB.</p> |
|
62 | - * |
|
63 | - * <p>Note that MaxFileSize cannot exceed <b>2 GB</b>.</p> |
|
64 | - * |
|
65 | - * @var integer |
|
66 | - */ |
|
67 | - private $maxFileSize = 10485760; |
|
51 | + /** |
|
52 | + * Set the maximum size that the output file is allowed to reach |
|
53 | + * before being rolled over to backup files. |
|
54 | + * |
|
55 | + * <p>In configuration files, the <var>MaxFileSize</var> option takes a |
|
56 | + * long integer in the range 0 - 2^63. You can specify the value |
|
57 | + * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
58 | + * interpreted being expressed respectively in kilobytes, megabytes |
|
59 | + * or gigabytes. For example, the value "10KB" will be interpreted |
|
60 | + * as 10240.</p> |
|
61 | + * <p>The default maximum file size is 10MB.</p> |
|
62 | + * |
|
63 | + * <p>Note that MaxFileSize cannot exceed <b>2 GB</b>.</p> |
|
64 | + * |
|
65 | + * @var integer |
|
66 | + */ |
|
67 | + private $maxFileSize = 10485760; |
|
68 | 68 | |
69 | - /** |
|
70 | - * Set the maximum number of backup files to keep around. |
|
71 | - * |
|
72 | - * <p>The <var>MaxBackupIndex</var> option determines how many backup |
|
73 | - * files are kept before the oldest is erased. This option takes |
|
74 | - * a positive integer value. If set to zero, then there will be no |
|
75 | - * backup files and the log file will be truncated when it reaches |
|
76 | - * MaxFileSize.</p> |
|
77 | - * <p>There is one backup file by default.</p> |
|
78 | - * |
|
79 | - * @var integer |
|
80 | - */ |
|
81 | - private $maxBackupIndex = 1; |
|
69 | + /** |
|
70 | + * Set the maximum number of backup files to keep around. |
|
71 | + * |
|
72 | + * <p>The <var>MaxBackupIndex</var> option determines how many backup |
|
73 | + * files are kept before the oldest is erased. This option takes |
|
74 | + * a positive integer value. If set to zero, then there will be no |
|
75 | + * backup files and the log file will be truncated when it reaches |
|
76 | + * MaxFileSize.</p> |
|
77 | + * <p>There is one backup file by default.</p> |
|
78 | + * |
|
79 | + * @var integer |
|
80 | + */ |
|
81 | + private $maxBackupIndex = 1; |
|
82 | 82 | |
83 | - /** |
|
84 | - * @var string the filename expanded |
|
85 | - * @access private |
|
86 | - */ |
|
87 | - private $expandedFileName = null; |
|
83 | + /** |
|
84 | + * @var string the filename expanded |
|
85 | + * @access private |
|
86 | + */ |
|
87 | + private $expandedFileName = null; |
|
88 | 88 | |
89 | - public function __destruct() { |
|
90 | - parent::__destruct(); |
|
91 | - } |
|
89 | + public function __destruct() { |
|
90 | + parent::__destruct(); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Returns the value of the MaxBackupIndex option. |
|
95 | - * @return integer |
|
96 | - */ |
|
97 | - private function getExpandedFileName() { |
|
98 | - return $this->expandedFileName; |
|
99 | - } |
|
93 | + /** |
|
94 | + * Returns the value of the MaxBackupIndex option. |
|
95 | + * @return integer |
|
96 | + */ |
|
97 | + private function getExpandedFileName() { |
|
98 | + return $this->expandedFileName; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the maximum size that the output file is allowed to reach |
|
103 | - * before being rolled over to backup files. |
|
104 | - * @return integer |
|
105 | - */ |
|
106 | - private function getMaximumFileSize() { |
|
107 | - return $this->maxFileSize; |
|
108 | - } |
|
101 | + /** |
|
102 | + * Get the maximum size that the output file is allowed to reach |
|
103 | + * before being rolled over to backup files. |
|
104 | + * @return integer |
|
105 | + */ |
|
106 | + private function getMaximumFileSize() { |
|
107 | + return $this->maxFileSize; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Implements the usual roll over behaviour. |
|
112 | - * |
|
113 | - * <p>If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex. |
|
114 | - * Moreover, File is renamed File.1 and closed. A new File is created to receive further log output. |
|
115 | - * |
|
116 | - * <p>If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created. |
|
117 | - */ |
|
118 | - private function rollOver() { |
|
119 | - // If maxBackups <= 0, then there is no file renaming to be done. |
|
120 | - if($this->maxBackupIndex > 0) { |
|
121 | - $fileName = $this->getExpandedFileName(); |
|
122 | - // Delete the oldest file, to keep Windows happy. |
|
123 | - $file = $fileName . '.' . $this->maxBackupIndex; |
|
124 | - if(is_writable($file)) |
|
125 | - unlink($file); |
|
126 | - // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} |
|
127 | - for($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { |
|
128 | - $file = $fileName . "." . $i; |
|
129 | - if(is_readable($file)) { |
|
130 | - $target = $fileName . '.' . ($i + 1); |
|
131 | - rename($file, $target); |
|
132 | - } |
|
133 | - } |
|
110 | + /** |
|
111 | + * Implements the usual roll over behaviour. |
|
112 | + * |
|
113 | + * <p>If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex. |
|
114 | + * Moreover, File is renamed File.1 and closed. A new File is created to receive further log output. |
|
115 | + * |
|
116 | + * <p>If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created. |
|
117 | + */ |
|
118 | + private function rollOver() { |
|
119 | + // If maxBackups <= 0, then there is no file renaming to be done. |
|
120 | + if($this->maxBackupIndex > 0) { |
|
121 | + $fileName = $this->getExpandedFileName(); |
|
122 | + // Delete the oldest file, to keep Windows happy. |
|
123 | + $file = $fileName . '.' . $this->maxBackupIndex; |
|
124 | + if(is_writable($file)) |
|
125 | + unlink($file); |
|
126 | + // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} |
|
127 | + for($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { |
|
128 | + $file = $fileName . "." . $i; |
|
129 | + if(is_readable($file)) { |
|
130 | + $target = $fileName . '.' . ($i + 1); |
|
131 | + rename($file, $target); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - $this->close(); |
|
135 | + $this->close(); |
|
136 | 136 | |
137 | - // Rename fileName to fileName.1 |
|
138 | - $target = $fileName . ".1"; |
|
139 | - $file = $fileName; |
|
140 | - rename($file, $target); |
|
141 | - } |
|
137 | + // Rename fileName to fileName.1 |
|
138 | + $target = $fileName . ".1"; |
|
139 | + $file = $fileName; |
|
140 | + rename($file, $target); |
|
141 | + } |
|
142 | 142 | |
143 | - //unset($this->fp); |
|
144 | - $this->activateOptions(); |
|
145 | - $this->setFile($fileName, false); |
|
146 | - } |
|
143 | + //unset($this->fp); |
|
144 | + $this->activateOptions(); |
|
145 | + $this->setFile($fileName, false); |
|
146 | + } |
|
147 | 147 | |
148 | - public function setFileName($fileName) { |
|
149 | - $this->fileName = $fileName; |
|
150 | - // As LoggerAppenderFile does not create the directory, it has to exist. |
|
151 | - // realpath() fails if the argument does not exist so the filename is separated. |
|
152 | - $this->expandedFileName = realpath(dirname($fileName)); |
|
153 | - if ($this->expandedFileName === false) throw new Exception("Directory of $fileName does not exist!"); |
|
154 | - $this->expandedFileName .= '/'.basename($fileName); |
|
155 | - } |
|
148 | + public function setFileName($fileName) { |
|
149 | + $this->fileName = $fileName; |
|
150 | + // As LoggerAppenderFile does not create the directory, it has to exist. |
|
151 | + // realpath() fails if the argument does not exist so the filename is separated. |
|
152 | + $this->expandedFileName = realpath(dirname($fileName)); |
|
153 | + if ($this->expandedFileName === false) throw new Exception("Directory of $fileName does not exist!"); |
|
154 | + $this->expandedFileName .= '/'.basename($fileName); |
|
155 | + } |
|
156 | 156 | |
157 | 157 | |
158 | - /** |
|
159 | - * Set the maximum number of backup files to keep around. |
|
160 | - * |
|
161 | - * <p>The <b>MaxBackupIndex</b> option determines how many backup |
|
162 | - * files are kept before the oldest is erased. This option takes |
|
163 | - * a positive integer value. If set to zero, then there will be no |
|
164 | - * backup files and the log file will be truncated when it reaches |
|
165 | - * MaxFileSize. |
|
166 | - * |
|
167 | - * @param mixed $maxBackups |
|
168 | - */ |
|
169 | - public function setMaxBackupIndex($maxBackups) { |
|
170 | - if(is_numeric($maxBackups)) { |
|
171 | - $this->maxBackupIndex = abs((int)$maxBackups); |
|
172 | - } |
|
173 | - } |
|
158 | + /** |
|
159 | + * Set the maximum number of backup files to keep around. |
|
160 | + * |
|
161 | + * <p>The <b>MaxBackupIndex</b> option determines how many backup |
|
162 | + * files are kept before the oldest is erased. This option takes |
|
163 | + * a positive integer value. If set to zero, then there will be no |
|
164 | + * backup files and the log file will be truncated when it reaches |
|
165 | + * MaxFileSize. |
|
166 | + * |
|
167 | + * @param mixed $maxBackups |
|
168 | + */ |
|
169 | + public function setMaxBackupIndex($maxBackups) { |
|
170 | + if(is_numeric($maxBackups)) { |
|
171 | + $this->maxBackupIndex = abs((int)$maxBackups); |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * Set the maximum size that the output file is allowed to reach |
|
177 | - * before being rolled over to backup files. |
|
178 | - * |
|
179 | - * @param mixed $maxFileSize |
|
180 | - * @see setMaxFileSize() |
|
181 | - * @deprecated |
|
182 | - */ |
|
183 | - public function setMaximumFileSize($maxFileSize) { |
|
184 | - return $this->setMaxFileSize($maxFileSize); |
|
185 | - } |
|
175 | + /** |
|
176 | + * Set the maximum size that the output file is allowed to reach |
|
177 | + * before being rolled over to backup files. |
|
178 | + * |
|
179 | + * @param mixed $maxFileSize |
|
180 | + * @see setMaxFileSize() |
|
181 | + * @deprecated |
|
182 | + */ |
|
183 | + public function setMaximumFileSize($maxFileSize) { |
|
184 | + return $this->setMaxFileSize($maxFileSize); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Set the maximum size that the output file is allowed to reach |
|
189 | - * before being rolled over to backup files. |
|
190 | - * <p>In configuration files, the <b>MaxFileSize</b> option takes an |
|
191 | - * long integer in the range 0 - 2^63. You can specify the value |
|
192 | - * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
193 | - * interpreted being expressed respectively in kilobytes, megabytes |
|
194 | - * or gigabytes. For example, the value "10KB" will be interpreted |
|
195 | - * as 10240. |
|
196 | - * |
|
197 | - * @param mixed $value |
|
198 | - * @return the actual file size set |
|
199 | - */ |
|
200 | - public function setMaxFileSize($value) { |
|
201 | - $maxFileSize = null; |
|
202 | - $numpart = substr($value,0, strlen($value) -2); |
|
203 | - $suffix = strtoupper(substr($value, -2)); |
|
187 | + /** |
|
188 | + * Set the maximum size that the output file is allowed to reach |
|
189 | + * before being rolled over to backup files. |
|
190 | + * <p>In configuration files, the <b>MaxFileSize</b> option takes an |
|
191 | + * long integer in the range 0 - 2^63. You can specify the value |
|
192 | + * with the suffixes "KB", "MB" or "GB" so that the integer is |
|
193 | + * interpreted being expressed respectively in kilobytes, megabytes |
|
194 | + * or gigabytes. For example, the value "10KB" will be interpreted |
|
195 | + * as 10240. |
|
196 | + * |
|
197 | + * @param mixed $value |
|
198 | + * @return the actual file size set |
|
199 | + */ |
|
200 | + public function setMaxFileSize($value) { |
|
201 | + $maxFileSize = null; |
|
202 | + $numpart = substr($value,0, strlen($value) -2); |
|
203 | + $suffix = strtoupper(substr($value, -2)); |
|
204 | 204 | |
205 | - switch($suffix) { |
|
206 | - case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break; |
|
207 | - case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break; |
|
208 | - case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break; |
|
209 | - default: |
|
210 | - if(is_numeric($value)) { |
|
211 | - $maxFileSize = (int)$value; |
|
212 | - } |
|
213 | - } |
|
205 | + switch($suffix) { |
|
206 | + case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break; |
|
207 | + case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break; |
|
208 | + case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break; |
|
209 | + default: |
|
210 | + if(is_numeric($value)) { |
|
211 | + $maxFileSize = (int)$value; |
|
212 | + } |
|
213 | + } |
|
214 | 214 | |
215 | - if($maxFileSize !== null) { |
|
216 | - $this->maxFileSize = abs($maxFileSize); |
|
217 | - } |
|
218 | - return $this->maxFileSize; |
|
219 | - } |
|
215 | + if($maxFileSize !== null) { |
|
216 | + $this->maxFileSize = abs($maxFileSize); |
|
217 | + } |
|
218 | + return $this->maxFileSize; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * @param LoggerLoggingEvent $event |
|
223 | - */ |
|
224 | - public function append(LoggerLoggingEvent $event) { |
|
225 | - parent::append($event); |
|
226 | - if(ftell($this->fp) > $this->getMaximumFileSize()) { |
|
227 | - $this->rollOver(); |
|
228 | - } |
|
229 | - } |
|
221 | + /** |
|
222 | + * @param LoggerLoggingEvent $event |
|
223 | + */ |
|
224 | + public function append(LoggerLoggingEvent $event) { |
|
225 | + parent::append($event); |
|
226 | + if(ftell($this->fp) > $this->getMaximumFileSize()) { |
|
227 | + $this->rollOver(); |
|
228 | + } |
|
229 | + } |
|
230 | 230 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @var integer |
80 | 80 | */ |
81 | - private $maxBackupIndex = 1; |
|
81 | + private $maxBackupIndex = 1; |
|
82 | 82 | |
83 | 83 | /** |
84 | 84 | * @var string the filename expanded |
@@ -117,17 +117,17 @@ discard block |
||
117 | 117 | */ |
118 | 118 | private function rollOver() { |
119 | 119 | // If maxBackups <= 0, then there is no file renaming to be done. |
120 | - if($this->maxBackupIndex > 0) { |
|
120 | + if ($this->maxBackupIndex > 0) { |
|
121 | 121 | $fileName = $this->getExpandedFileName(); |
122 | 122 | // Delete the oldest file, to keep Windows happy. |
123 | - $file = $fileName . '.' . $this->maxBackupIndex; |
|
124 | - if(is_writable($file)) |
|
123 | + $file = $fileName.'.'.$this->maxBackupIndex; |
|
124 | + if (is_writable($file)) |
|
125 | 125 | unlink($file); |
126 | 126 | // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} |
127 | - for($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { |
|
128 | - $file = $fileName . "." . $i; |
|
129 | - if(is_readable($file)) { |
|
130 | - $target = $fileName . '.' . ($i + 1); |
|
127 | + for ($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { |
|
128 | + $file = $fileName.".".$i; |
|
129 | + if (is_readable($file)) { |
|
130 | + $target = $fileName.'.'.($i + 1); |
|
131 | 131 | rename($file, $target); |
132 | 132 | } |
133 | 133 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $this->close(); |
136 | 136 | |
137 | 137 | // Rename fileName to fileName.1 |
138 | - $target = $fileName . ".1"; |
|
138 | + $target = $fileName.".1"; |
|
139 | 139 | $file = $fileName; |
140 | 140 | rename($file, $target); |
141 | 141 | } |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @param mixed $maxBackups |
168 | 168 | */ |
169 | 169 | public function setMaxBackupIndex($maxBackups) { |
170 | - if(is_numeric($maxBackups)) { |
|
171 | - $this->maxBackupIndex = abs((int)$maxBackups); |
|
170 | + if (is_numeric($maxBackups)) { |
|
171 | + $this->maxBackupIndex = abs((int) $maxBackups); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -199,20 +199,20 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function setMaxFileSize($value) { |
201 | 201 | $maxFileSize = null; |
202 | - $numpart = substr($value,0, strlen($value) -2); |
|
202 | + $numpart = substr($value, 0, strlen($value) - 2); |
|
203 | 203 | $suffix = strtoupper(substr($value, -2)); |
204 | 204 | |
205 | - switch($suffix) { |
|
206 | - case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break; |
|
207 | - case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break; |
|
208 | - case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break; |
|
205 | + switch ($suffix) { |
|
206 | + case 'KB': $maxFileSize = (int) ((int) $numpart * 1024); break; |
|
207 | + case 'MB': $maxFileSize = (int) ((int) $numpart * 1024 * 1024); break; |
|
208 | + case 'GB': $maxFileSize = (int) ((int) $numpart * 1024 * 1024 * 1024); break; |
|
209 | 209 | default: |
210 | - if(is_numeric($value)) { |
|
211 | - $maxFileSize = (int)$value; |
|
210 | + if (is_numeric($value)) { |
|
211 | + $maxFileSize = (int) $value; |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if($maxFileSize !== null) { |
|
215 | + if ($maxFileSize !== null) { |
|
216 | 216 | $this->maxFileSize = abs($maxFileSize); |
217 | 217 | } |
218 | 218 | return $this->maxFileSize; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function append(LoggerLoggingEvent $event) { |
225 | 225 | parent::append($event); |
226 | - if(ftell($this->fp) > $this->getMaximumFileSize()) { |
|
226 | + if (ftell($this->fp) > $this->getMaximumFileSize()) { |
|
227 | 227 | $this->rollOver(); |
228 | 228 | } |
229 | 229 | } |
@@ -121,8 +121,9 @@ discard block |
||
121 | 121 | $fileName = $this->getExpandedFileName(); |
122 | 122 | // Delete the oldest file, to keep Windows happy. |
123 | 123 | $file = $fileName . '.' . $this->maxBackupIndex; |
124 | - if(is_writable($file)) |
|
125 | - unlink($file); |
|
124 | + if(is_writable($file)) { |
|
125 | + unlink($file); |
|
126 | + } |
|
126 | 127 | // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} |
127 | 128 | for($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { |
128 | 129 | $file = $fileName . "." . $i; |
@@ -150,7 +151,9 @@ discard block |
||
150 | 151 | // As LoggerAppenderFile does not create the directory, it has to exist. |
151 | 152 | // realpath() fails if the argument does not exist so the filename is separated. |
152 | 153 | $this->expandedFileName = realpath(dirname($fileName)); |
153 | - if ($this->expandedFileName === false) throw new Exception("Directory of $fileName does not exist!"); |
|
154 | + if ($this->expandedFileName === false) { |
|
155 | + throw new Exception("Directory of $fileName does not exist!"); |
|
156 | + } |
|
154 | 157 | $this->expandedFileName .= '/'.basename($fileName); |
155 | 158 | } |
156 | 159 |
@@ -225,6 +225,7 @@ |
||
225 | 225 | |
226 | 226 | /** |
227 | 227 | * @param mixed |
228 | + * @param boolean $flag |
|
228 | 229 | */ |
229 | 230 | public function setUseXml($flag) { |
230 | 231 | $this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml()); |
@@ -46,215 +46,215 @@ |
||
46 | 46 | */ |
47 | 47 | class LoggerAppenderSocket extends LoggerAppender { |
48 | 48 | |
49 | - /** |
|
50 | - * @var mixed socket connection resource |
|
51 | - * @access private |
|
52 | - */ |
|
53 | - private $sp = false; |
|
49 | + /** |
|
50 | + * @var mixed socket connection resource |
|
51 | + * @access private |
|
52 | + */ |
|
53 | + private $sp = false; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Target host. On how to define remote hostaname see |
|
57 | - * {@link PHP_MANUAL#fsockopen} |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - private $remoteHost = ''; |
|
55 | + /** |
|
56 | + * Target host. On how to define remote hostaname see |
|
57 | + * {@link PHP_MANUAL#fsockopen} |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + private $remoteHost = ''; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var integer the network port. |
|
64 | - */ |
|
65 | - private $port = 4446; |
|
62 | + /** |
|
63 | + * @var integer the network port. |
|
64 | + */ |
|
65 | + private $port = 4446; |
|
66 | 66 | |
67 | - /** |
|
68 | - * @var boolean get event's location info. |
|
69 | - */ |
|
70 | - private $locationInfo = false; |
|
67 | + /** |
|
68 | + * @var boolean get event's location info. |
|
69 | + */ |
|
70 | + private $locationInfo = false; |
|
71 | 71 | |
72 | - /** |
|
73 | - * @var integer connection timeout |
|
74 | - */ |
|
75 | - private $timeout = 30; |
|
72 | + /** |
|
73 | + * @var integer connection timeout |
|
74 | + */ |
|
75 | + private $timeout = 30; |
|
76 | 76 | |
77 | - /** |
|
78 | - * @var boolean output events via {@link LoggerXmlLayout} |
|
79 | - */ |
|
80 | - private $useXml = false; |
|
77 | + /** |
|
78 | + * @var boolean output events via {@link LoggerXmlLayout} |
|
79 | + */ |
|
80 | + private $useXml = false; |
|
81 | 81 | |
82 | - /** |
|
83 | - * @var boolean forward this option to {@link LoggerXmlLayout}. |
|
84 | - * Ignored if {@link $useXml} is <i>false</i>. |
|
85 | - */ |
|
86 | - private $log4jNamespace = false; |
|
82 | + /** |
|
83 | + * @var boolean forward this option to {@link LoggerXmlLayout}. |
|
84 | + * Ignored if {@link $useXml} is <i>false</i>. |
|
85 | + */ |
|
86 | + private $log4jNamespace = false; |
|
87 | 87 | |
88 | - /** |
|
89 | - * @var LoggerXmlLayout |
|
90 | - * @access private |
|
91 | - */ |
|
92 | - private $xmlLayout = null; |
|
88 | + /** |
|
89 | + * @var LoggerXmlLayout |
|
90 | + * @access private |
|
91 | + */ |
|
92 | + private $xmlLayout = null; |
|
93 | 93 | |
94 | - /** @var indiciates if this appender should run in dry mode */ |
|
95 | - private $dry = false; |
|
94 | + /** @var indiciates if this appender should run in dry mode */ |
|
95 | + private $dry = false; |
|
96 | 96 | |
97 | - public function __destruct() { |
|
98 | - $this->close(); |
|
99 | - } |
|
97 | + public function __destruct() { |
|
98 | + $this->close(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Create a socket connection using defined parameters |
|
103 | - */ |
|
104 | - public function activateOptions() { |
|
105 | - if(!$this->dry) { |
|
106 | - $this->sp = @fsockopen($this->getRemoteHost(), $this->getPort(), $errno, $errstr, $this->getTimeout()); |
|
107 | - if ($this->sp === false) { |
|
108 | - throw new LoggerException("Could not open socket to ".$this->getRemoteHost().":".$this->getPort().": $errstr ($errno)"); |
|
109 | - } |
|
110 | - } |
|
111 | - if($this->getUseXml()) { |
|
112 | - $this->xmlLayout = LoggerReflectionUtils::createObject('LoggerLayoutXml'); |
|
113 | - if($this->xmlLayout === null) { |
|
114 | - $this->setUseXml(false); |
|
115 | - } else { |
|
116 | - $this->xmlLayout->setLocationInfo($this->getLocationInfo()); |
|
117 | - $this->xmlLayout->setLog4jNamespace($this->getLog4jNamespace()); |
|
118 | - $this->xmlLayout->activateOptions(); |
|
119 | - } |
|
120 | - } |
|
101 | + /** |
|
102 | + * Create a socket connection using defined parameters |
|
103 | + */ |
|
104 | + public function activateOptions() { |
|
105 | + if(!$this->dry) { |
|
106 | + $this->sp = @fsockopen($this->getRemoteHost(), $this->getPort(), $errno, $errstr, $this->getTimeout()); |
|
107 | + if ($this->sp === false) { |
|
108 | + throw new LoggerException("Could not open socket to ".$this->getRemoteHost().":".$this->getPort().": $errstr ($errno)"); |
|
109 | + } |
|
110 | + } |
|
111 | + if($this->getUseXml()) { |
|
112 | + $this->xmlLayout = LoggerReflectionUtils::createObject('LoggerLayoutXml'); |
|
113 | + if($this->xmlLayout === null) { |
|
114 | + $this->setUseXml(false); |
|
115 | + } else { |
|
116 | + $this->xmlLayout->setLocationInfo($this->getLocationInfo()); |
|
117 | + $this->xmlLayout->setLog4jNamespace($this->getLog4jNamespace()); |
|
118 | + $this->xmlLayout->activateOptions(); |
|
119 | + } |
|
120 | + } |
|
121 | 121 | $this->closed = false; |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - public function close() { |
|
125 | - if($this->closed != true) { |
|
126 | - if(!$this->dry and $this->sp !== false) { |
|
127 | - fclose($this->sp); |
|
128 | - } |
|
129 | - $this->closed = true; |
|
130 | - } |
|
131 | - } |
|
124 | + public function close() { |
|
125 | + if($this->closed != true) { |
|
126 | + if(!$this->dry and $this->sp !== false) { |
|
127 | + fclose($this->sp); |
|
128 | + } |
|
129 | + $this->closed = true; |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - public function setDry($dry) { |
|
134 | - $this->dry = $dry; |
|
135 | - } |
|
133 | + public function setDry($dry) { |
|
134 | + $this->dry = $dry; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function getHostname() { |
|
141 | - return $this->getRemoteHost(); |
|
142 | - } |
|
137 | + /** |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function getHostname() { |
|
141 | + return $this->getRemoteHost(); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @return boolean |
|
146 | - */ |
|
147 | - public function getLocationInfo() { |
|
148 | - return $this->locationInfo; |
|
149 | - } |
|
144 | + /** |
|
145 | + * @return boolean |
|
146 | + */ |
|
147 | + public function getLocationInfo() { |
|
148 | + return $this->locationInfo; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return boolean |
|
153 | - */ |
|
154 | - public function getLog4jNamespace() { |
|
155 | - return $this->log4jNamespace; |
|
156 | - } |
|
151 | + /** |
|
152 | + * @return boolean |
|
153 | + */ |
|
154 | + public function getLog4jNamespace() { |
|
155 | + return $this->log4jNamespace; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @return integer |
|
160 | - */ |
|
161 | - public function getPort() { |
|
162 | - return $this->port; |
|
163 | - } |
|
158 | + /** |
|
159 | + * @return integer |
|
160 | + */ |
|
161 | + public function getPort() { |
|
162 | + return $this->port; |
|
163 | + } |
|
164 | 164 | |
165 | - public function getRemoteHost() { |
|
166 | - return $this->remoteHost; |
|
167 | - } |
|
165 | + public function getRemoteHost() { |
|
166 | + return $this->remoteHost; |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * @return integer |
|
171 | - */ |
|
172 | - public function getTimeout() { |
|
173 | - return $this->timeout; |
|
174 | - } |
|
169 | + /** |
|
170 | + * @return integer |
|
171 | + */ |
|
172 | + public function getTimeout() { |
|
173 | + return $this->timeout; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @var boolean |
|
178 | - */ |
|
179 | - public function getUseXml() { |
|
180 | - return $this->useXml; |
|
181 | - } |
|
176 | + /** |
|
177 | + * @var boolean |
|
178 | + */ |
|
179 | + public function getUseXml() { |
|
180 | + return $this->useXml; |
|
181 | + } |
|
182 | 182 | |
183 | - public function reset() { |
|
184 | - $this->close(); |
|
185 | - parent::reset(); |
|
186 | - } |
|
183 | + public function reset() { |
|
184 | + $this->close(); |
|
185 | + parent::reset(); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @param mixed |
|
190 | - */ |
|
191 | - public function setLocationInfo($flag) { |
|
192 | - $this->locationInfo = LoggerOptionConverter::toBoolean($flag, $this->getLocationInfo()); |
|
193 | - } |
|
188 | + /** |
|
189 | + * @param mixed |
|
190 | + */ |
|
191 | + public function setLocationInfo($flag) { |
|
192 | + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, $this->getLocationInfo()); |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @param mixed |
|
197 | - */ |
|
198 | - public function setLog4jNamespace($flag) { |
|
199 | - $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, $this->getLog4jNamespace()); |
|
200 | - } |
|
195 | + /** |
|
196 | + * @param mixed |
|
197 | + */ |
|
198 | + public function setLog4jNamespace($flag) { |
|
199 | + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, $this->getLog4jNamespace()); |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * @param integer |
|
204 | - */ |
|
205 | - public function setPort($port) { |
|
206 | - $port = LoggerOptionConverter::toInt($port, 0); |
|
207 | - if($port > 0 and $port < 65535) { |
|
208 | - $this->port = $port; |
|
209 | - } |
|
210 | - } |
|
202 | + /** |
|
203 | + * @param integer |
|
204 | + */ |
|
205 | + public function setPort($port) { |
|
206 | + $port = LoggerOptionConverter::toInt($port, 0); |
|
207 | + if($port > 0 and $port < 65535) { |
|
208 | + $this->port = $port; |
|
209 | + } |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * @param string |
|
214 | - */ |
|
215 | - public function setRemoteHost($hostname) { |
|
216 | - $this->remoteHost = $hostname; |
|
217 | - } |
|
212 | + /** |
|
213 | + * @param string |
|
214 | + */ |
|
215 | + public function setRemoteHost($hostname) { |
|
216 | + $this->remoteHost = $hostname; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @param integer |
|
221 | - */ |
|
222 | - public function setTimeout($timeout) { |
|
223 | - $this->timeout = LoggerOptionConverter::toInt($timeout, $this->getTimeout()); |
|
224 | - } |
|
219 | + /** |
|
220 | + * @param integer |
|
221 | + */ |
|
222 | + public function setTimeout($timeout) { |
|
223 | + $this->timeout = LoggerOptionConverter::toInt($timeout, $this->getTimeout()); |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * @param mixed |
|
228 | - */ |
|
229 | - public function setUseXml($flag) { |
|
230 | - $this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml()); |
|
231 | - } |
|
226 | + /** |
|
227 | + * @param mixed |
|
228 | + */ |
|
229 | + public function setUseXml($flag) { |
|
230 | + $this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml()); |
|
231 | + } |
|
232 | 232 | |
233 | - public function append(LoggerLoggingEvent $event) { |
|
234 | - if($this->sp || $this->dry) { |
|
235 | - if($this->getLocationInfo()) { |
|
236 | - $event->getLocationInformation(); |
|
237 | - } |
|
233 | + public function append(LoggerLoggingEvent $event) { |
|
234 | + if($this->sp || $this->dry) { |
|
235 | + if($this->getLocationInfo()) { |
|
236 | + $event->getLocationInformation(); |
|
237 | + } |
|
238 | 238 | |
239 | - if(!$this->getUseXml()) { |
|
240 | - $sEvent = serialize($event); |
|
241 | - if(!$this->dry) { |
|
242 | - fwrite($this->sp, $sEvent, strlen($sEvent)); |
|
243 | - } else { |
|
244 | - echo "DRY MODE OF SOCKET APPENDER: ".$sEvent; |
|
245 | - } |
|
246 | - } else { |
|
247 | - if(!$this->dry) { |
|
248 | - fwrite($this->sp, $this->xmlLayout->format($event)); |
|
249 | - } else { |
|
250 | - echo "DRY MODE OF SOCKET APPENDER: ".$this->xmlLayout->format($event); |
|
251 | - } |
|
252 | - } |
|
239 | + if(!$this->getUseXml()) { |
|
240 | + $sEvent = serialize($event); |
|
241 | + if(!$this->dry) { |
|
242 | + fwrite($this->sp, $sEvent, strlen($sEvent)); |
|
243 | + } else { |
|
244 | + echo "DRY MODE OF SOCKET APPENDER: ".$sEvent; |
|
245 | + } |
|
246 | + } else { |
|
247 | + if(!$this->dry) { |
|
248 | + fwrite($this->sp, $this->xmlLayout->format($event)); |
|
249 | + } else { |
|
250 | + echo "DRY MODE OF SOCKET APPENDER: ".$this->xmlLayout->format($event); |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | - // not sure about it... |
|
255 | - if(!$this->dry) { |
|
256 | - fflush($this->sp); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
254 | + // not sure about it... |
|
255 | + if(!$this->dry) { |
|
256 | + fflush($this->sp); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | } |
@@ -102,15 +102,15 @@ discard block |
||
102 | 102 | * Create a socket connection using defined parameters |
103 | 103 | */ |
104 | 104 | public function activateOptions() { |
105 | - if(!$this->dry) { |
|
105 | + if (!$this->dry) { |
|
106 | 106 | $this->sp = @fsockopen($this->getRemoteHost(), $this->getPort(), $errno, $errstr, $this->getTimeout()); |
107 | 107 | if ($this->sp === false) { |
108 | 108 | throw new LoggerException("Could not open socket to ".$this->getRemoteHost().":".$this->getPort().": $errstr ($errno)"); |
109 | 109 | } |
110 | 110 | } |
111 | - if($this->getUseXml()) { |
|
111 | + if ($this->getUseXml()) { |
|
112 | 112 | $this->xmlLayout = LoggerReflectionUtils::createObject('LoggerLayoutXml'); |
113 | - if($this->xmlLayout === null) { |
|
113 | + if ($this->xmlLayout === null) { |
|
114 | 114 | $this->setUseXml(false); |
115 | 115 | } else { |
116 | 116 | $this->xmlLayout->setLocationInfo($this->getLocationInfo()); |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | public function close() { |
125 | - if($this->closed != true) { |
|
126 | - if(!$this->dry and $this->sp !== false) { |
|
125 | + if ($this->closed != true) { |
|
126 | + if (!$this->dry and $this->sp !== false) { |
|
127 | 127 | fclose($this->sp); |
128 | 128 | } |
129 | 129 | $this->closed = true; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function setPort($port) { |
206 | 206 | $port = LoggerOptionConverter::toInt($port, 0); |
207 | - if($port > 0 and $port < 65535) { |
|
207 | + if ($port > 0 and $port < 65535) { |
|
208 | 208 | $this->port = $port; |
209 | 209 | } |
210 | 210 | } |
@@ -231,20 +231,20 @@ discard block |
||
231 | 231 | } |
232 | 232 | |
233 | 233 | public function append(LoggerLoggingEvent $event) { |
234 | - if($this->sp || $this->dry) { |
|
235 | - if($this->getLocationInfo()) { |
|
234 | + if ($this->sp || $this->dry) { |
|
235 | + if ($this->getLocationInfo()) { |
|
236 | 236 | $event->getLocationInformation(); |
237 | 237 | } |
238 | 238 | |
239 | - if(!$this->getUseXml()) { |
|
239 | + if (!$this->getUseXml()) { |
|
240 | 240 | $sEvent = serialize($event); |
241 | - if(!$this->dry) { |
|
241 | + if (!$this->dry) { |
|
242 | 242 | fwrite($this->sp, $sEvent, strlen($sEvent)); |
243 | 243 | } else { |
244 | 244 | echo "DRY MODE OF SOCKET APPENDER: ".$sEvent; |
245 | 245 | } |
246 | 246 | } else { |
247 | - if(!$this->dry) { |
|
247 | + if (!$this->dry) { |
|
248 | 248 | fwrite($this->sp, $this->xmlLayout->format($event)); |
249 | 249 | } else { |
250 | 250 | echo "DRY MODE OF SOCKET APPENDER: ".$this->xmlLayout->format($event); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | // not sure about it... |
255 | - if(!$this->dry) { |
|
255 | + if (!$this->dry) { |
|
256 | 256 | fflush($this->sp); |
257 | 257 | } |
258 | 258 | } |
@@ -279,7 +279,6 @@ |
||
279 | 279 | * |
280 | 280 | * @param string $url The name of the configuration file where the |
281 | 281 | * configuration information is stored. |
282 | - * @param LoggerHierarchy $repository the repository to apply the configuration |
|
283 | 282 | */ |
284 | 283 | public function configure(LoggerHierarchy $hierarchy, $url = '') { |
285 | 284 | $properties = @parse_ini_file($url); |
@@ -313,16 +313,16 @@ discard block |
||
313 | 313 | $effectivePrefix = self::ROOT_LOGGER_PREFIX; |
314 | 314 | $value = @$props[self::ROOT_LOGGER_PREFIX]; |
315 | 315 | |
316 | - if(empty($value)) { |
|
316 | + if (empty($value)) { |
|
317 | 317 | $value = @$props[self::ROOT_CATEGORY_PREFIX]; |
318 | 318 | $effectivePrefix = self::ROOT_CATEGORY_PREFIX; |
319 | 319 | } |
320 | 320 | |
321 | - if(empty($value)) { |
|
321 | + if (empty($value)) { |
|
322 | 322 | // TODO "Could not find root logger information. Is this OK?" |
323 | 323 | } else { |
324 | 324 | $root = $hierarchy->getRootLogger(); |
325 | - $this->parseCategory($props, $root, $effectivePrefix, self::INTERNAL_ROOT_NAME, $value); |
|
325 | + $this->parseCategory($props, $root, $effectivePrefix, self::INTERNAL_ROOT_NAME, $value); |
|
326 | 326 | } |
327 | 327 | } |
328 | 328 | |
@@ -333,19 +333,19 @@ discard block |
||
333 | 333 | * @param LoggerHierarchy $hierarchy |
334 | 334 | */ |
335 | 335 | private function parseCatsAndRenderers($props, LoggerHierarchy $hierarchy) { |
336 | - while(list($key,$value) = each($props)) { |
|
337 | - if(strpos($key, self::CATEGORY_PREFIX) === 0 or |
|
336 | + while (list($key, $value) = each($props)) { |
|
337 | + if (strpos($key, self::CATEGORY_PREFIX) === 0 or |
|
338 | 338 | strpos($key, self::LOGGER_PREFIX) === 0) { |
339 | - if(strpos($key, self::CATEGORY_PREFIX) === 0) { |
|
339 | + if (strpos($key, self::CATEGORY_PREFIX) === 0) { |
|
340 | 340 | $loggerName = substr($key, strlen(self::CATEGORY_PREFIX)); |
341 | - } else if(strpos($key, self::LOGGER_PREFIX) === 0) { |
|
341 | + } else if (strpos($key, self::LOGGER_PREFIX) === 0) { |
|
342 | 342 | $loggerName = substr($key, strlen(self::LOGGER_PREFIX)); |
343 | 343 | } |
344 | 344 | |
345 | 345 | $logger = $hierarchy->getLogger($loggerName); |
346 | 346 | $this->parseCategory($props, $logger, $key, $loggerName, $value); |
347 | 347 | $this->parseAdditivityForLogger($props, $logger, $loggerName); |
348 | - } else if(strpos($key, self::RENDERER_PREFIX) === 0) { |
|
348 | + } else if (strpos($key, self::RENDERER_PREFIX) === 0) { |
|
349 | 349 | $renderedClass = substr($key, strlen(self::RENDERER_PREFIX)); |
350 | 350 | $renderingClass = $value; |
351 | 351 | $hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass); |
@@ -361,10 +361,10 @@ discard block |
||
361 | 361 | * @param string $loggerName |
362 | 362 | */ |
363 | 363 | private function parseAdditivityForLogger($props, Logger $cat, $loggerName) { |
364 | - $value = LoggerOptionConverter::findAndSubst(self::ADDITIVITY_PREFIX . $loggerName, $props); |
|
364 | + $value = LoggerOptionConverter::findAndSubst(self::ADDITIVITY_PREFIX.$loggerName, $props); |
|
365 | 365 | |
366 | 366 | // touch additivity only if necessary |
367 | - if(!empty($value)) { |
|
367 | + if (!empty($value)) { |
|
368 | 368 | $additivity = LoggerOptionConverter::toBoolean($value, true); |
369 | 369 | $cat->setAdditivity($additivity); |
370 | 370 | } |
@@ -387,9 +387,9 @@ discard block |
||
387 | 387 | // If value is not in the form ", appender.." or "", then we should set |
388 | 388 | // the level of the loggeregory. |
389 | 389 | |
390 | - if(!(empty($value) || @$value[0] == ',')) { |
|
390 | + if (!(empty($value) || @$value[0] == ',')) { |
|
391 | 391 | // just to be on the safe side... |
392 | - if(count($st) == 0) { |
|
392 | + if (count($st) == 0) { |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | $levelStr = current($st); |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | // If the level value is inherited, set category level value to |
398 | 398 | // null. We also check that the user has not specified inherited for the |
399 | 399 | // root category. |
400 | - if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { |
|
401 | - if($loggerName == self::INTERNAL_ROOT_NAME) { |
|
400 | + if ('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { |
|
401 | + if ($loggerName == self::INTERNAL_ROOT_NAME) { |
|
402 | 402 | // TODO: throw exception? "The root logger cannot be set to null." |
403 | 403 | } else { |
404 | 404 | $logger->setLevel(null); |
@@ -410,14 +410,14 @@ discard block |
||
410 | 410 | |
411 | 411 | // TODO: removing should be done by the logger, if necessary and wanted |
412 | 412 | // $logger->removeAllAppenders(); |
413 | - while($appenderName = next($st)) { |
|
413 | + while ($appenderName = next($st)) { |
|
414 | 414 | $appenderName = trim($appenderName); |
415 | - if(empty($appenderName)) { |
|
415 | + if (empty($appenderName)) { |
|
416 | 416 | continue; |
417 | 417 | } |
418 | 418 | |
419 | 419 | $appender = $this->parseAppender($props, $appenderName); |
420 | - if($appender !== null) { |
|
420 | + if ($appender !== null) { |
|
421 | 421 | $logger->addAppender($appender); |
422 | 422 | } |
423 | 423 | } |
@@ -430,34 +430,34 @@ discard block |
||
430 | 430 | */ |
431 | 431 | private function parseAppender($props, $appenderName) { |
432 | 432 | $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
433 | - $prefix = self::APPENDER_PREFIX . $appenderName; |
|
434 | - if($appender === null) { |
|
433 | + $prefix = self::APPENDER_PREFIX.$appenderName; |
|
434 | + if ($appender === null) { |
|
435 | 435 | // Appender was not previously initialized. |
436 | 436 | $appenderClass = @$props[$prefix]; |
437 | 437 | $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderClass); |
438 | - if($appender === null) { |
|
438 | + if ($appender === null) { |
|
439 | 439 | return null; |
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
443 | - if($appender->requiresLayout() ) { |
|
444 | - $layoutPrefix = $prefix . ".layout"; |
|
443 | + if ($appender->requiresLayout()) { |
|
444 | + $layoutPrefix = $prefix.".layout"; |
|
445 | 445 | $layoutClass = @$props[$layoutPrefix]; |
446 | 446 | $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); |
447 | - if(empty($layoutClass)) { |
|
447 | + if (empty($layoutClass)) { |
|
448 | 448 | $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
449 | 449 | } else { |
450 | 450 | $layout = LoggerReflectionUtils::createObject($layoutClass); |
451 | - if($layout === null) { |
|
451 | + if ($layout === null) { |
|
452 | 452 | $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
453 | 453 | } |
454 | 454 | } |
455 | 455 | |
456 | - LoggerReflectionUtils::setPropertiesByObject($layout, $props, $layoutPrefix . "."); |
|
456 | + LoggerReflectionUtils::setPropertiesByObject($layout, $props, $layoutPrefix."."); |
|
457 | 457 | $appender->setLayout($layout); |
458 | 458 | |
459 | 459 | } |
460 | - LoggerReflectionUtils::setPropertiesByObject($appender, $props, $prefix . "."); |
|
460 | + LoggerReflectionUtils::setPropertiesByObject($appender, $props, $prefix."."); |
|
461 | 461 | return $appender; |
462 | 462 | } |
463 | 463 | } |
@@ -63,401 +63,401 @@ |
||
63 | 63 | * @since 0.5 |
64 | 64 | */ |
65 | 65 | class LoggerConfiguratorIni implements LoggerConfigurator { |
66 | - const CATEGORY_PREFIX = "log4php.category."; |
|
67 | - const LOGGER_PREFIX = "log4php.logger."; |
|
68 | - const FACTORY_PREFIX = "log4php.factory"; |
|
69 | - const ADDITIVITY_PREFIX = "log4php.additivity."; |
|
70 | - const ROOT_CATEGORY_PREFIX = "log4php.rootCategory"; |
|
71 | - const ROOT_LOGGER_PREFIX = "log4php.rootLogger"; |
|
72 | - const APPENDER_PREFIX = "log4php.appender."; |
|
73 | - const RENDERER_PREFIX = "log4php.renderer."; |
|
74 | - const THRESHOLD_PREFIX = "log4php.threshold"; |
|
66 | + const CATEGORY_PREFIX = "log4php.category."; |
|
67 | + const LOGGER_PREFIX = "log4php.logger."; |
|
68 | + const FACTORY_PREFIX = "log4php.factory"; |
|
69 | + const ADDITIVITY_PREFIX = "log4php.additivity."; |
|
70 | + const ROOT_CATEGORY_PREFIX = "log4php.rootCategory"; |
|
71 | + const ROOT_LOGGER_PREFIX = "log4php.rootLogger"; |
|
72 | + const APPENDER_PREFIX = "log4php.appender."; |
|
73 | + const RENDERER_PREFIX = "log4php.renderer."; |
|
74 | + const THRESHOLD_PREFIX = "log4php.threshold"; |
|
75 | 75 | |
76 | - /** |
|
77 | - * Key for specifying the {@link LoggerFactory}. |
|
78 | - */ |
|
79 | - const LOGGER_FACTORY_KEY = "log4php.loggerFactory"; |
|
80 | - const LOGGER_DEBUG_KEY = "log4php.debug"; |
|
81 | - const INTERNAL_ROOT_NAME = "root"; |
|
76 | + /** |
|
77 | + * Key for specifying the {@link LoggerFactory}. |
|
78 | + */ |
|
79 | + const LOGGER_FACTORY_KEY = "log4php.loggerFactory"; |
|
80 | + const LOGGER_DEBUG_KEY = "log4php.debug"; |
|
81 | + const INTERNAL_ROOT_NAME = "root"; |
|
82 | 82 | |
83 | - /** |
|
84 | - * Constructor |
|
85 | - */ |
|
86 | - public function __construct() { |
|
87 | - } |
|
83 | + /** |
|
84 | + * Constructor |
|
85 | + */ |
|
86 | + public function __construct() { |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Read configuration from a file. |
|
91 | - * |
|
92 | - * <p>The function {@link PHP_MANUAL#parse_ini_file} is used to read the |
|
93 | - * file.</p> |
|
94 | - * |
|
95 | - * <b>The existing configuration is not cleared nor reset.</b> |
|
96 | - * If you require a different behavior, then call |
|
97 | - * {@link Logger::resetConfiguration()} |
|
98 | - * method before calling {@link doConfigure()}. |
|
99 | - * |
|
100 | - * <p>The configuration file consists of statements in the format |
|
101 | - * <b>key=value</b>. The syntax of different configuration |
|
102 | - * elements are discussed below. |
|
103 | - * |
|
104 | - * <p><b>Repository-wide threshold</b></p> |
|
105 | - * |
|
106 | - * <p>The repository-wide threshold filters logging requests by level |
|
107 | - * regardless of logger. The syntax is: |
|
108 | - * |
|
109 | - * <pre> |
|
110 | - * log4php.threshold=[level] |
|
111 | - * </pre> |
|
112 | - * |
|
113 | - * <p>The level value can consist of the string values OFF, FATAL, |
|
114 | - * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
115 | - * custom level value can be specified in the form |
|
116 | - * <samp>level#classname</samp>. By default the repository-wide threshold is set |
|
117 | - * to the lowest possible value, namely the level <b>ALL</b>. |
|
118 | - * </p> |
|
119 | - * |
|
120 | - * |
|
121 | - * <p><b>Appender configuration</b></p> |
|
122 | - * |
|
123 | - * <p>Appender configuration syntax is:</p> |
|
124 | - * <pre> |
|
125 | - * ; For appender named <i>appenderName</i>, set its class. |
|
126 | - * ; Note: The appender name can contain dots. |
|
127 | - * log4php.appender.appenderName=name_of_appender_class |
|
128 | - * |
|
129 | - * ; Set appender specific options. |
|
130 | - * |
|
131 | - * log4php.appender.appenderName.option1=value1 |
|
132 | - * log4php.appender.appenderName.optionN=valueN |
|
133 | - * </pre> |
|
134 | - * |
|
135 | - * For each named appender you can configure its {@link LoggerLayout}. The |
|
136 | - * syntax for configuring an appender's layout is: |
|
137 | - * <pre> |
|
138 | - * log4php.appender.appenderName.layout=name_of_layout_class |
|
139 | - * log4php.appender.appenderName.layout.option1=value1 |
|
140 | - * .... |
|
141 | - * log4php.appender.appenderName.layout.optionN=valueN |
|
142 | - * </pre> |
|
143 | - * |
|
144 | - * <p><b>Configuring loggers</b></p> |
|
145 | - * |
|
146 | - * <p>The syntax for configuring the root logger is: |
|
147 | - * <pre> |
|
148 | - * log4php.rootLogger=[level], appenderName, appenderName, ... |
|
149 | - * </pre> |
|
150 | - * |
|
151 | - * <p>This syntax means that an optional <i>level</i> can be |
|
152 | - * supplied followed by appender names separated by commas. |
|
153 | - * |
|
154 | - * <p>The level value can consist of the string values OFF, FATAL, |
|
155 | - * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
156 | - * custom level value can be specified in the form</p> |
|
157 | - * |
|
158 | - * <pre>level#classname</pre> |
|
159 | - * |
|
160 | - * <p>If a level value is specified, then the root level is set |
|
161 | - * to the corresponding level. If no level value is specified, |
|
162 | - * then the root level remains untouched. |
|
163 | - * |
|
164 | - * <p>The root logger can be assigned multiple appenders. |
|
165 | - * |
|
166 | - * <p>Each <i>appenderName</i> (separated by commas) will be added to |
|
167 | - * the root logger. The named appender is defined using the |
|
168 | - * appender syntax defined above. |
|
169 | - * |
|
170 | - * <p>For non-root categories the syntax is almost the same: |
|
171 | - * <pre> |
|
172 | - * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... |
|
173 | - * </pre> |
|
174 | - * |
|
175 | - * <p>The meaning of the optional level value is discussed above |
|
176 | - * in relation to the root logger. In addition however, the value |
|
177 | - * INHERITED can be specified meaning that the named logger should |
|
178 | - * inherit its level from the logger hierarchy.</p> |
|
179 | - * |
|
180 | - * <p>If no level value is supplied, then the level of the |
|
181 | - * named logger remains untouched.</p> |
|
182 | - * |
|
183 | - * <p>By default categories inherit their level from the |
|
184 | - * hierarchy. However, if you set the level of a logger and later |
|
185 | - * decide that that logger should inherit its level, then you should |
|
186 | - * specify INHERITED as the value for the level value. NULL is a |
|
187 | - * synonym for INHERITED.</p> |
|
188 | - * |
|
189 | - * <p>Similar to the root logger syntax, each <i>appenderName</i> |
|
190 | - * (separated by commas) will be attached to the named logger.</p> |
|
191 | - * |
|
192 | - * <p>See the <i>appender additivity rule</i> in the user manual for |
|
193 | - * the meaning of the <b>additivity</b> flag. |
|
194 | - * |
|
195 | - * <p><b>ObjectRenderers</b></p> |
|
196 | - * |
|
197 | - * <p>You can customize the way message objects of a given type are |
|
198 | - * converted to String before being logged. This is done by |
|
199 | - * specifying a {@link LoggerRendererObject} |
|
200 | - * for the object type would like to customize.</p> |
|
201 | - * |
|
202 | - * <p>The syntax is: |
|
203 | - * |
|
204 | - * <pre> |
|
205 | - * log4php.renderer.name_of_rendered_class=name_of_rendering.class |
|
206 | - * </pre> |
|
207 | - * |
|
208 | - * As in, |
|
209 | - * <pre> |
|
210 | - * log4php.renderer.myFruit=myFruitRenderer |
|
211 | - * </pre> |
|
212 | - * |
|
213 | - * <p><b>Logger Factories</b></p> |
|
214 | - * |
|
215 | - * The usage of custom logger factories is discouraged and no longer |
|
216 | - * documented. |
|
217 | - * |
|
218 | - * <p><b>Example</b></p> |
|
219 | - * |
|
220 | - * <p>An example configuration is given below. Other configuration |
|
221 | - * file examples are given in the <b>tests</b> folder. |
|
222 | - * |
|
223 | - * <pre> |
|
224 | - * ; Set options for appender named "A1". |
|
225 | - * ; Appender "A1" will be a LoggerAppenderSyslog |
|
226 | - * log4php.appender.A1=LoggerAppenderSyslog |
|
227 | - * |
|
228 | - * ; The syslog daemon resides on www.abc.net |
|
229 | - * log4php.appender.A1.ident=log4php-test |
|
230 | - * |
|
231 | - * ; A1's layout is a LoggerPatternLayout, using the conversion pattern |
|
232 | - * ; <b>%r %-5p %c{2} %M.%L %x - %m%n</b>. Thus, the log output will |
|
233 | - * ; include the relative time since the start of the application in |
|
234 | - * ; milliseconds, followed by the level of the log request, |
|
235 | - * ; followed by the two rightmost components of the logger name, |
|
236 | - * ; followed by the callers method name, followed by the line number, |
|
237 | - * ; the nested disgnostic context and finally the message itself. |
|
238 | - * ; Refer to the documentation of LoggerPatternLayout} for further information |
|
239 | - * ; on the syntax of the ConversionPattern key. |
|
240 | - * log4php.appender.A1.layout=LoggerPatternLayout |
|
241 | - * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n" |
|
242 | - * |
|
243 | - * ; Set options for appender named "A2" |
|
244 | - * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB |
|
245 | - * ; using at most one backup file. A2's layout is TTCC, using the |
|
246 | - * ; ISO8061 date format with context printing enabled. |
|
247 | - * log4php.appender.A2=LoggerAppenderRollingFile |
|
248 | - * log4php.appender.A2.MaxFileSize=10MB |
|
249 | - * log4php.appender.A2.MaxBackupIndex=1 |
|
250 | - * log4php.appender.A2.layout=LoggerLayoutTTCC |
|
251 | - * log4php.appender.A2.layout.ContextPrinting="true" |
|
252 | - * log4php.appender.A2.layout.DateFormat="%c" |
|
253 | - * |
|
254 | - * ; Root logger set to DEBUG using the A2 appender defined above. |
|
255 | - * log4php.rootLogger=DEBUG, A2 |
|
256 | - * |
|
257 | - * ; Logger definitions: |
|
258 | - * ; The SECURITY logger inherits is level from root. However, it's output |
|
259 | - * ; will go to A1 appender defined above. It's additivity is non-cumulative. |
|
260 | - * log4php.logger.SECURITY=INHERIT, A1 |
|
261 | - * log4php.additivity.SECURITY=false |
|
262 | - * |
|
263 | - * ; Only warnings or above will be logged for the logger "SECURITY.access". |
|
264 | - * ; Output will go to A1. |
|
265 | - * log4php.logger.SECURITY.access=WARN |
|
266 | - * |
|
267 | - * |
|
268 | - * ; The logger "class.of.the.day" inherits its level from the |
|
269 | - * ; logger hierarchy. Output will go to the appender's of the root |
|
270 | - * ; logger, A2 in this case. |
|
271 | - * log4php.logger.class.of.the.day=INHERIT |
|
272 | - * </pre> |
|
273 | - * |
|
274 | - * <p>Refer to the <b>setOption</b> method in each Appender and |
|
275 | - * Layout for class specific options.</p> |
|
276 | - * |
|
277 | - * <p>Use the <b>";"</b> character at the |
|
278 | - * beginning of a line for comments.</p> |
|
279 | - * |
|
280 | - * @param string $url The name of the configuration file where the |
|
281 | - * configuration information is stored. |
|
282 | - * @param LoggerHierarchy $repository the repository to apply the configuration |
|
283 | - */ |
|
284 | - public function configure(LoggerHierarchy $hierarchy, $url = '') { |
|
285 | - $properties = @parse_ini_file($url); |
|
286 | - if ($properties === false || count($properties) == 0) { |
|
287 | - $error = error_get_last(); |
|
288 | - throw new LoggerException("LoggerConfiguratorIni: ".$error['message']); |
|
289 | - } |
|
290 | - return $this->doConfigureProperties($properties, $hierarchy); |
|
291 | - } |
|
89 | + /** |
|
90 | + * Read configuration from a file. |
|
91 | + * |
|
92 | + * <p>The function {@link PHP_MANUAL#parse_ini_file} is used to read the |
|
93 | + * file.</p> |
|
94 | + * |
|
95 | + * <b>The existing configuration is not cleared nor reset.</b> |
|
96 | + * If you require a different behavior, then call |
|
97 | + * {@link Logger::resetConfiguration()} |
|
98 | + * method before calling {@link doConfigure()}. |
|
99 | + * |
|
100 | + * <p>The configuration file consists of statements in the format |
|
101 | + * <b>key=value</b>. The syntax of different configuration |
|
102 | + * elements are discussed below. |
|
103 | + * |
|
104 | + * <p><b>Repository-wide threshold</b></p> |
|
105 | + * |
|
106 | + * <p>The repository-wide threshold filters logging requests by level |
|
107 | + * regardless of logger. The syntax is: |
|
108 | + * |
|
109 | + * <pre> |
|
110 | + * log4php.threshold=[level] |
|
111 | + * </pre> |
|
112 | + * |
|
113 | + * <p>The level value can consist of the string values OFF, FATAL, |
|
114 | + * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
115 | + * custom level value can be specified in the form |
|
116 | + * <samp>level#classname</samp>. By default the repository-wide threshold is set |
|
117 | + * to the lowest possible value, namely the level <b>ALL</b>. |
|
118 | + * </p> |
|
119 | + * |
|
120 | + * |
|
121 | + * <p><b>Appender configuration</b></p> |
|
122 | + * |
|
123 | + * <p>Appender configuration syntax is:</p> |
|
124 | + * <pre> |
|
125 | + * ; For appender named <i>appenderName</i>, set its class. |
|
126 | + * ; Note: The appender name can contain dots. |
|
127 | + * log4php.appender.appenderName=name_of_appender_class |
|
128 | + * |
|
129 | + * ; Set appender specific options. |
|
130 | + * |
|
131 | + * log4php.appender.appenderName.option1=value1 |
|
132 | + * log4php.appender.appenderName.optionN=valueN |
|
133 | + * </pre> |
|
134 | + * |
|
135 | + * For each named appender you can configure its {@link LoggerLayout}. The |
|
136 | + * syntax for configuring an appender's layout is: |
|
137 | + * <pre> |
|
138 | + * log4php.appender.appenderName.layout=name_of_layout_class |
|
139 | + * log4php.appender.appenderName.layout.option1=value1 |
|
140 | + * .... |
|
141 | + * log4php.appender.appenderName.layout.optionN=valueN |
|
142 | + * </pre> |
|
143 | + * |
|
144 | + * <p><b>Configuring loggers</b></p> |
|
145 | + * |
|
146 | + * <p>The syntax for configuring the root logger is: |
|
147 | + * <pre> |
|
148 | + * log4php.rootLogger=[level], appenderName, appenderName, ... |
|
149 | + * </pre> |
|
150 | + * |
|
151 | + * <p>This syntax means that an optional <i>level</i> can be |
|
152 | + * supplied followed by appender names separated by commas. |
|
153 | + * |
|
154 | + * <p>The level value can consist of the string values OFF, FATAL, |
|
155 | + * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A |
|
156 | + * custom level value can be specified in the form</p> |
|
157 | + * |
|
158 | + * <pre>level#classname</pre> |
|
159 | + * |
|
160 | + * <p>If a level value is specified, then the root level is set |
|
161 | + * to the corresponding level. If no level value is specified, |
|
162 | + * then the root level remains untouched. |
|
163 | + * |
|
164 | + * <p>The root logger can be assigned multiple appenders. |
|
165 | + * |
|
166 | + * <p>Each <i>appenderName</i> (separated by commas) will be added to |
|
167 | + * the root logger. The named appender is defined using the |
|
168 | + * appender syntax defined above. |
|
169 | + * |
|
170 | + * <p>For non-root categories the syntax is almost the same: |
|
171 | + * <pre> |
|
172 | + * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... |
|
173 | + * </pre> |
|
174 | + * |
|
175 | + * <p>The meaning of the optional level value is discussed above |
|
176 | + * in relation to the root logger. In addition however, the value |
|
177 | + * INHERITED can be specified meaning that the named logger should |
|
178 | + * inherit its level from the logger hierarchy.</p> |
|
179 | + * |
|
180 | + * <p>If no level value is supplied, then the level of the |
|
181 | + * named logger remains untouched.</p> |
|
182 | + * |
|
183 | + * <p>By default categories inherit their level from the |
|
184 | + * hierarchy. However, if you set the level of a logger and later |
|
185 | + * decide that that logger should inherit its level, then you should |
|
186 | + * specify INHERITED as the value for the level value. NULL is a |
|
187 | + * synonym for INHERITED.</p> |
|
188 | + * |
|
189 | + * <p>Similar to the root logger syntax, each <i>appenderName</i> |
|
190 | + * (separated by commas) will be attached to the named logger.</p> |
|
191 | + * |
|
192 | + * <p>See the <i>appender additivity rule</i> in the user manual for |
|
193 | + * the meaning of the <b>additivity</b> flag. |
|
194 | + * |
|
195 | + * <p><b>ObjectRenderers</b></p> |
|
196 | + * |
|
197 | + * <p>You can customize the way message objects of a given type are |
|
198 | + * converted to String before being logged. This is done by |
|
199 | + * specifying a {@link LoggerRendererObject} |
|
200 | + * for the object type would like to customize.</p> |
|
201 | + * |
|
202 | + * <p>The syntax is: |
|
203 | + * |
|
204 | + * <pre> |
|
205 | + * log4php.renderer.name_of_rendered_class=name_of_rendering.class |
|
206 | + * </pre> |
|
207 | + * |
|
208 | + * As in, |
|
209 | + * <pre> |
|
210 | + * log4php.renderer.myFruit=myFruitRenderer |
|
211 | + * </pre> |
|
212 | + * |
|
213 | + * <p><b>Logger Factories</b></p> |
|
214 | + * |
|
215 | + * The usage of custom logger factories is discouraged and no longer |
|
216 | + * documented. |
|
217 | + * |
|
218 | + * <p><b>Example</b></p> |
|
219 | + * |
|
220 | + * <p>An example configuration is given below. Other configuration |
|
221 | + * file examples are given in the <b>tests</b> folder. |
|
222 | + * |
|
223 | + * <pre> |
|
224 | + * ; Set options for appender named "A1". |
|
225 | + * ; Appender "A1" will be a LoggerAppenderSyslog |
|
226 | + * log4php.appender.A1=LoggerAppenderSyslog |
|
227 | + * |
|
228 | + * ; The syslog daemon resides on www.abc.net |
|
229 | + * log4php.appender.A1.ident=log4php-test |
|
230 | + * |
|
231 | + * ; A1's layout is a LoggerPatternLayout, using the conversion pattern |
|
232 | + * ; <b>%r %-5p %c{2} %M.%L %x - %m%n</b>. Thus, the log output will |
|
233 | + * ; include the relative time since the start of the application in |
|
234 | + * ; milliseconds, followed by the level of the log request, |
|
235 | + * ; followed by the two rightmost components of the logger name, |
|
236 | + * ; followed by the callers method name, followed by the line number, |
|
237 | + * ; the nested disgnostic context and finally the message itself. |
|
238 | + * ; Refer to the documentation of LoggerPatternLayout} for further information |
|
239 | + * ; on the syntax of the ConversionPattern key. |
|
240 | + * log4php.appender.A1.layout=LoggerPatternLayout |
|
241 | + * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n" |
|
242 | + * |
|
243 | + * ; Set options for appender named "A2" |
|
244 | + * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB |
|
245 | + * ; using at most one backup file. A2's layout is TTCC, using the |
|
246 | + * ; ISO8061 date format with context printing enabled. |
|
247 | + * log4php.appender.A2=LoggerAppenderRollingFile |
|
248 | + * log4php.appender.A2.MaxFileSize=10MB |
|
249 | + * log4php.appender.A2.MaxBackupIndex=1 |
|
250 | + * log4php.appender.A2.layout=LoggerLayoutTTCC |
|
251 | + * log4php.appender.A2.layout.ContextPrinting="true" |
|
252 | + * log4php.appender.A2.layout.DateFormat="%c" |
|
253 | + * |
|
254 | + * ; Root logger set to DEBUG using the A2 appender defined above. |
|
255 | + * log4php.rootLogger=DEBUG, A2 |
|
256 | + * |
|
257 | + * ; Logger definitions: |
|
258 | + * ; The SECURITY logger inherits is level from root. However, it's output |
|
259 | + * ; will go to A1 appender defined above. It's additivity is non-cumulative. |
|
260 | + * log4php.logger.SECURITY=INHERIT, A1 |
|
261 | + * log4php.additivity.SECURITY=false |
|
262 | + * |
|
263 | + * ; Only warnings or above will be logged for the logger "SECURITY.access". |
|
264 | + * ; Output will go to A1. |
|
265 | + * log4php.logger.SECURITY.access=WARN |
|
266 | + * |
|
267 | + * |
|
268 | + * ; The logger "class.of.the.day" inherits its level from the |
|
269 | + * ; logger hierarchy. Output will go to the appender's of the root |
|
270 | + * ; logger, A2 in this case. |
|
271 | + * log4php.logger.class.of.the.day=INHERIT |
|
272 | + * </pre> |
|
273 | + * |
|
274 | + * <p>Refer to the <b>setOption</b> method in each Appender and |
|
275 | + * Layout for class specific options.</p> |
|
276 | + * |
|
277 | + * <p>Use the <b>";"</b> character at the |
|
278 | + * beginning of a line for comments.</p> |
|
279 | + * |
|
280 | + * @param string $url The name of the configuration file where the |
|
281 | + * configuration information is stored. |
|
282 | + * @param LoggerHierarchy $repository the repository to apply the configuration |
|
283 | + */ |
|
284 | + public function configure(LoggerHierarchy $hierarchy, $url = '') { |
|
285 | + $properties = @parse_ini_file($url); |
|
286 | + if ($properties === false || count($properties) == 0) { |
|
287 | + $error = error_get_last(); |
|
288 | + throw new LoggerException("LoggerConfiguratorIni: ".$error['message']); |
|
289 | + } |
|
290 | + return $this->doConfigureProperties($properties, $hierarchy); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * Read configuration options from <b>properties</b>. |
|
295 | - * |
|
296 | - * @see doConfigure(). |
|
297 | - * @param array $properties |
|
298 | - * @param LoggerHierarchy $hierarchy |
|
299 | - */ |
|
300 | - private function doConfigureProperties($properties, LoggerHierarchy $hierarchy) { |
|
301 | - $thresholdStr = @$properties[self::THRESHOLD_PREFIX]; |
|
302 | - $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll())); |
|
303 | - $this->configureRootCategory($properties, $hierarchy); |
|
304 | - $this->parseCatsAndRenderers($properties, $hierarchy); |
|
305 | - return true; |
|
306 | - } |
|
293 | + /** |
|
294 | + * Read configuration options from <b>properties</b>. |
|
295 | + * |
|
296 | + * @see doConfigure(). |
|
297 | + * @param array $properties |
|
298 | + * @param LoggerHierarchy $hierarchy |
|
299 | + */ |
|
300 | + private function doConfigureProperties($properties, LoggerHierarchy $hierarchy) { |
|
301 | + $thresholdStr = @$properties[self::THRESHOLD_PREFIX]; |
|
302 | + $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll())); |
|
303 | + $this->configureRootCategory($properties, $hierarchy); |
|
304 | + $this->parseCatsAndRenderers($properties, $hierarchy); |
|
305 | + return true; |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * @param array $props array of properties |
|
310 | - * @param LoggerHierarchy $hierarchy |
|
311 | - */ |
|
312 | - private function configureRootCategory($props, LoggerHierarchy $hierarchy) { |
|
313 | - $effectivePrefix = self::ROOT_LOGGER_PREFIX; |
|
314 | - $value = @$props[self::ROOT_LOGGER_PREFIX]; |
|
308 | + /** |
|
309 | + * @param array $props array of properties |
|
310 | + * @param LoggerHierarchy $hierarchy |
|
311 | + */ |
|
312 | + private function configureRootCategory($props, LoggerHierarchy $hierarchy) { |
|
313 | + $effectivePrefix = self::ROOT_LOGGER_PREFIX; |
|
314 | + $value = @$props[self::ROOT_LOGGER_PREFIX]; |
|
315 | 315 | |
316 | - if(empty($value)) { |
|
317 | - $value = @$props[self::ROOT_CATEGORY_PREFIX]; |
|
318 | - $effectivePrefix = self::ROOT_CATEGORY_PREFIX; |
|
319 | - } |
|
316 | + if(empty($value)) { |
|
317 | + $value = @$props[self::ROOT_CATEGORY_PREFIX]; |
|
318 | + $effectivePrefix = self::ROOT_CATEGORY_PREFIX; |
|
319 | + } |
|
320 | 320 | |
321 | - if(empty($value)) { |
|
322 | - // TODO "Could not find root logger information. Is this OK?" |
|
323 | - } else { |
|
324 | - $root = $hierarchy->getRootLogger(); |
|
325 | - $this->parseCategory($props, $root, $effectivePrefix, self::INTERNAL_ROOT_NAME, $value); |
|
326 | - } |
|
327 | - } |
|
321 | + if(empty($value)) { |
|
322 | + // TODO "Could not find root logger information. Is this OK?" |
|
323 | + } else { |
|
324 | + $root = $hierarchy->getRootLogger(); |
|
325 | + $this->parseCategory($props, $root, $effectivePrefix, self::INTERNAL_ROOT_NAME, $value); |
|
326 | + } |
|
327 | + } |
|
328 | 328 | |
329 | - /** |
|
330 | - * Parse non-root elements, such non-root categories and renderers. |
|
331 | - * |
|
332 | - * @param array $props array of properties |
|
333 | - * @param LoggerHierarchy $hierarchy |
|
334 | - */ |
|
335 | - private function parseCatsAndRenderers($props, LoggerHierarchy $hierarchy) { |
|
336 | - while(list($key,$value) = each($props)) { |
|
337 | - if(strpos($key, self::CATEGORY_PREFIX) === 0 or |
|
338 | - strpos($key, self::LOGGER_PREFIX) === 0) { |
|
339 | - if(strpos($key, self::CATEGORY_PREFIX) === 0) { |
|
340 | - $loggerName = substr($key, strlen(self::CATEGORY_PREFIX)); |
|
341 | - } else if(strpos($key, self::LOGGER_PREFIX) === 0) { |
|
342 | - $loggerName = substr($key, strlen(self::LOGGER_PREFIX)); |
|
343 | - } |
|
329 | + /** |
|
330 | + * Parse non-root elements, such non-root categories and renderers. |
|
331 | + * |
|
332 | + * @param array $props array of properties |
|
333 | + * @param LoggerHierarchy $hierarchy |
|
334 | + */ |
|
335 | + private function parseCatsAndRenderers($props, LoggerHierarchy $hierarchy) { |
|
336 | + while(list($key,$value) = each($props)) { |
|
337 | + if(strpos($key, self::CATEGORY_PREFIX) === 0 or |
|
338 | + strpos($key, self::LOGGER_PREFIX) === 0) { |
|
339 | + if(strpos($key, self::CATEGORY_PREFIX) === 0) { |
|
340 | + $loggerName = substr($key, strlen(self::CATEGORY_PREFIX)); |
|
341 | + } else if(strpos($key, self::LOGGER_PREFIX) === 0) { |
|
342 | + $loggerName = substr($key, strlen(self::LOGGER_PREFIX)); |
|
343 | + } |
|
344 | 344 | |
345 | - $logger = $hierarchy->getLogger($loggerName); |
|
346 | - $this->parseCategory($props, $logger, $key, $loggerName, $value); |
|
347 | - $this->parseAdditivityForLogger($props, $logger, $loggerName); |
|
348 | - } else if(strpos($key, self::RENDERER_PREFIX) === 0) { |
|
349 | - $renderedClass = substr($key, strlen(self::RENDERER_PREFIX)); |
|
350 | - $renderingClass = $value; |
|
351 | - $hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
345 | + $logger = $hierarchy->getLogger($loggerName); |
|
346 | + $this->parseCategory($props, $logger, $key, $loggerName, $value); |
|
347 | + $this->parseAdditivityForLogger($props, $logger, $loggerName); |
|
348 | + } else if(strpos($key, self::RENDERER_PREFIX) === 0) { |
|
349 | + $renderedClass = substr($key, strlen(self::RENDERER_PREFIX)); |
|
350 | + $renderingClass = $value; |
|
351 | + $hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | 355 | |
356 | - /** |
|
357 | - * Parse the additivity option for a non-root category. |
|
358 | - * |
|
359 | - * @param array $props array of properties |
|
360 | - * @param Logger $cat |
|
361 | - * @param string $loggerName |
|
362 | - */ |
|
363 | - private function parseAdditivityForLogger($props, Logger $cat, $loggerName) { |
|
364 | - $value = LoggerOptionConverter::findAndSubst(self::ADDITIVITY_PREFIX . $loggerName, $props); |
|
356 | + /** |
|
357 | + * Parse the additivity option for a non-root category. |
|
358 | + * |
|
359 | + * @param array $props array of properties |
|
360 | + * @param Logger $cat |
|
361 | + * @param string $loggerName |
|
362 | + */ |
|
363 | + private function parseAdditivityForLogger($props, Logger $cat, $loggerName) { |
|
364 | + $value = LoggerOptionConverter::findAndSubst(self::ADDITIVITY_PREFIX . $loggerName, $props); |
|
365 | 365 | |
366 | - // touch additivity only if necessary |
|
367 | - if(!empty($value)) { |
|
368 | - $additivity = LoggerOptionConverter::toBoolean($value, true); |
|
369 | - $cat->setAdditivity($additivity); |
|
370 | - } |
|
371 | - } |
|
366 | + // touch additivity only if necessary |
|
367 | + if(!empty($value)) { |
|
368 | + $additivity = LoggerOptionConverter::toBoolean($value, true); |
|
369 | + $cat->setAdditivity($additivity); |
|
370 | + } |
|
371 | + } |
|
372 | 372 | |
373 | - /** |
|
374 | - * This method must work for the root category as well. |
|
375 | - * |
|
376 | - * @param array $props array of properties |
|
377 | - * @param Logger $logger |
|
378 | - * @param string $optionKey |
|
379 | - * @param string $loggerName |
|
380 | - * @param string $value |
|
381 | - * @return Logger |
|
382 | - */ |
|
383 | - private function parseCategory($props, Logger $logger, $optionKey, $loggerName, $value) { |
|
384 | - // We must skip over ',' but not white space |
|
385 | - $st = explode(',', $value); |
|
373 | + /** |
|
374 | + * This method must work for the root category as well. |
|
375 | + * |
|
376 | + * @param array $props array of properties |
|
377 | + * @param Logger $logger |
|
378 | + * @param string $optionKey |
|
379 | + * @param string $loggerName |
|
380 | + * @param string $value |
|
381 | + * @return Logger |
|
382 | + */ |
|
383 | + private function parseCategory($props, Logger $logger, $optionKey, $loggerName, $value) { |
|
384 | + // We must skip over ',' but not white space |
|
385 | + $st = explode(',', $value); |
|
386 | 386 | |
387 | - // If value is not in the form ", appender.." or "", then we should set |
|
388 | - // the level of the loggeregory. |
|
387 | + // If value is not in the form ", appender.." or "", then we should set |
|
388 | + // the level of the loggeregory. |
|
389 | 389 | |
390 | - if(!(empty($value) || @$value[0] == ',')) { |
|
391 | - // just to be on the safe side... |
|
392 | - if(count($st) == 0) { |
|
393 | - return; |
|
394 | - } |
|
395 | - $levelStr = current($st); |
|
390 | + if(!(empty($value) || @$value[0] == ',')) { |
|
391 | + // just to be on the safe side... |
|
392 | + if(count($st) == 0) { |
|
393 | + return; |
|
394 | + } |
|
395 | + $levelStr = current($st); |
|
396 | 396 | |
397 | - // If the level value is inherited, set category level value to |
|
398 | - // null. We also check that the user has not specified inherited for the |
|
399 | - // root category. |
|
400 | - if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { |
|
401 | - if($loggerName == self::INTERNAL_ROOT_NAME) { |
|
402 | - // TODO: throw exception? "The root logger cannot be set to null." |
|
403 | - } else { |
|
404 | - $logger->setLevel(null); |
|
405 | - } |
|
406 | - } else { |
|
407 | - $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug())); |
|
408 | - } |
|
409 | - } |
|
397 | + // If the level value is inherited, set category level value to |
|
398 | + // null. We also check that the user has not specified inherited for the |
|
399 | + // root category. |
|
400 | + if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { |
|
401 | + if($loggerName == self::INTERNAL_ROOT_NAME) { |
|
402 | + // TODO: throw exception? "The root logger cannot be set to null." |
|
403 | + } else { |
|
404 | + $logger->setLevel(null); |
|
405 | + } |
|
406 | + } else { |
|
407 | + $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug())); |
|
408 | + } |
|
409 | + } |
|
410 | 410 | |
411 | - // TODO: removing should be done by the logger, if necessary and wanted |
|
412 | - // $logger->removeAllAppenders(); |
|
413 | - while($appenderName = next($st)) { |
|
414 | - $appenderName = trim($appenderName); |
|
415 | - if(empty($appenderName)) { |
|
416 | - continue; |
|
417 | - } |
|
411 | + // TODO: removing should be done by the logger, if necessary and wanted |
|
412 | + // $logger->removeAllAppenders(); |
|
413 | + while($appenderName = next($st)) { |
|
414 | + $appenderName = trim($appenderName); |
|
415 | + if(empty($appenderName)) { |
|
416 | + continue; |
|
417 | + } |
|
418 | 418 | |
419 | - $appender = $this->parseAppender($props, $appenderName); |
|
420 | - if($appender !== null) { |
|
421 | - $logger->addAppender($appender); |
|
422 | - } |
|
423 | - } |
|
424 | - } |
|
419 | + $appender = $this->parseAppender($props, $appenderName); |
|
420 | + if($appender !== null) { |
|
421 | + $logger->addAppender($appender); |
|
422 | + } |
|
423 | + } |
|
424 | + } |
|
425 | 425 | |
426 | - /** |
|
427 | - * @param array $props array of properties |
|
428 | - * @param string $appenderName |
|
429 | - * @return LoggerAppender |
|
430 | - */ |
|
431 | - private function parseAppender($props, $appenderName) { |
|
432 | - $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
433 | - $prefix = self::APPENDER_PREFIX . $appenderName; |
|
434 | - if($appender === null) { |
|
435 | - // Appender was not previously initialized. |
|
436 | - $appenderClass = @$props[$prefix]; |
|
437 | - $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderClass); |
|
438 | - if($appender === null) { |
|
439 | - return null; |
|
440 | - } |
|
441 | - } |
|
426 | + /** |
|
427 | + * @param array $props array of properties |
|
428 | + * @param string $appenderName |
|
429 | + * @return LoggerAppender |
|
430 | + */ |
|
431 | + private function parseAppender($props, $appenderName) { |
|
432 | + $appender = LoggerAppenderPool::getAppenderFromPool($appenderName); |
|
433 | + $prefix = self::APPENDER_PREFIX . $appenderName; |
|
434 | + if($appender === null) { |
|
435 | + // Appender was not previously initialized. |
|
436 | + $appenderClass = @$props[$prefix]; |
|
437 | + $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderClass); |
|
438 | + if($appender === null) { |
|
439 | + return null; |
|
440 | + } |
|
441 | + } |
|
442 | 442 | |
443 | - if($appender->requiresLayout() ) { |
|
444 | - $layoutPrefix = $prefix . ".layout"; |
|
445 | - $layoutClass = @$props[$layoutPrefix]; |
|
446 | - $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); |
|
447 | - if(empty($layoutClass)) { |
|
448 | - $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
449 | - } else { |
|
450 | - $layout = LoggerReflectionUtils::createObject($layoutClass); |
|
451 | - if($layout === null) { |
|
452 | - $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
453 | - } |
|
454 | - } |
|
443 | + if($appender->requiresLayout() ) { |
|
444 | + $layoutPrefix = $prefix . ".layout"; |
|
445 | + $layoutClass = @$props[$layoutPrefix]; |
|
446 | + $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); |
|
447 | + if(empty($layoutClass)) { |
|
448 | + $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
449 | + } else { |
|
450 | + $layout = LoggerReflectionUtils::createObject($layoutClass); |
|
451 | + if($layout === null) { |
|
452 | + $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple'); |
|
453 | + } |
|
454 | + } |
|
455 | 455 | |
456 | - LoggerReflectionUtils::setPropertiesByObject($layout, $props, $layoutPrefix . "."); |
|
457 | - $appender->setLayout($layout); |
|
456 | + LoggerReflectionUtils::setPropertiesByObject($layout, $props, $layoutPrefix . "."); |
|
457 | + $appender->setLayout($layout); |
|
458 | 458 | |
459 | - } |
|
460 | - LoggerReflectionUtils::setPropertiesByObject($appender, $props, $prefix . "."); |
|
461 | - return $appender; |
|
462 | - } |
|
459 | + } |
|
460 | + LoggerReflectionUtils::setPropertiesByObject($appender, $props, $prefix . "."); |
|
461 | + return $appender; |
|
462 | + } |
|
463 | 463 | } |
@@ -237,6 +237,9 @@ |
||
237 | 237 | return $this->head; |
238 | 238 | } |
239 | 239 | |
240 | + /** |
|
241 | + * @param string $c |
|
242 | + */ |
|
240 | 243 | public function finalizeConverter($c) { |
241 | 244 | $pc = null; |
242 | 245 | switch($c) { |
@@ -186,19 +186,19 @@ |
||
186 | 186 | case self::CONVERTER_STATE: |
187 | 187 | $this->currentLiteral .= $c; |
188 | 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 | - } |
|
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 | 202 | } // switch |
203 | 203 | break; |
204 | 204 | case self::MIN_STATE: |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function __construct($pattern) { |
92 | 92 | $this->pattern = $pattern; |
93 | - $this->patternLength = strlen($pattern); |
|
93 | + $this->patternLength = strlen($pattern); |
|
94 | 94 | $this->formattingInfo = new LoggerFormattingInfo(); |
95 | 95 | $this->state = self::LITERAL_STATE; |
96 | 96 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param LoggerPatternConverter $pc |
100 | 100 | */ |
101 | 101 | public function addToList($pc) { |
102 | - if($this->head == null) { |
|
102 | + if ($this->head == null) { |
|
103 | 103 | $this->head = $pc; |
104 | 104 | $this->tail = $this->head; |
105 | 105 | } else { |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return string |
113 | 113 | */ |
114 | 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) { |
|
115 | + if (($this->i < $this->patternLength) and ($this->pattern{$this->i} == '{')) { |
|
116 | + $end = strpos($this->pattern, '}', $this->i); |
|
117 | + if ($end !== false) { |
|
118 | 118 | $r = substr($this->pattern, ($this->i + 1), ($end - $this->i - 1)); |
119 | - $this->i= $end + 1; |
|
119 | + $this->i = $end + 1; |
|
120 | 120 | return $r; |
121 | 121 | } |
122 | 122 | } |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | public function extractPrecisionOption() { |
131 | 131 | $opt = $this->extractOption(); |
132 | 132 | $r = 0; |
133 | - if($opt !== null) { |
|
134 | - if(is_numeric($opt)) { |
|
135 | - $r = (int)$opt; |
|
136 | - if($r <= 0) { |
|
133 | + if ($opt !== null) { |
|
134 | + if (is_numeric($opt)) { |
|
135 | + $r = (int) $opt; |
|
136 | + if ($r <= 0) { |
|
137 | 137 | $r = 0; |
138 | 138 | } |
139 | 139 | } |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | $c = ''; |
151 | 151 | $this->i = 0; |
152 | 152 | $this->currentLiteral = ''; |
153 | - while($this->i < $this->patternLength) { |
|
153 | + while ($this->i < $this->patternLength) { |
|
154 | 154 | $c = $this->pattern{$this->i++}; |
155 | 155 | |
156 | - switch($this->state) { |
|
156 | + switch ($this->state) { |
|
157 | 157 | case self::LITERAL_STATE: |
158 | 158 | // In literal state, the last char is always a literal. |
159 | - if($this->i == $this->patternLength) { |
|
159 | + if ($this->i == $this->patternLength) { |
|
160 | 160 | $this->currentLiteral .= $c; |
161 | 161 | continue; |
162 | 162 | } |
163 | - if($c == self::ESCAPE_CHAR) { |
|
163 | + if ($c == self::ESCAPE_CHAR) { |
|
164 | 164 | // peek at the next char. |
165 | - switch($this->pattern{$this->i}) { |
|
165 | + switch ($this->pattern{$this->i}) { |
|
166 | 166 | case self::ESCAPE_CHAR: |
167 | 167 | $this->currentLiteral .= $c; |
168 | 168 | $this->i++; // move pointer |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $this->i++; // move pointer |
173 | 173 | break; |
174 | 174 | default: |
175 | - if(strlen($this->currentLiteral) != 0) { |
|
175 | + if (strlen($this->currentLiteral) != 0) { |
|
176 | 176 | $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
177 | 177 | } |
178 | 178 | $this->currentLiteral = $c; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | break; |
186 | 186 | case self::CONVERTER_STATE: |
187 | 187 | $this->currentLiteral .= $c; |
188 | - switch($c) { |
|
188 | + switch ($c) { |
|
189 | 189 | case '-': |
190 | 190 | $this->formattingInfo->leftAlign = true; |
191 | 191 | break; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $this->state = self::DOT_STATE; |
194 | 194 | break; |
195 | 195 | default: |
196 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
196 | + if (ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
197 | 197 | $this->formattingInfo->min = ord($c) - ord('0'); |
198 | 198 | $this->state = self::MIN_STATE; |
199 | 199 | } else { |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | break; |
204 | 204 | case self::MIN_STATE: |
205 | 205 | $this->currentLiteral .= $c; |
206 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
206 | + if (ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
207 | 207 | $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0')); |
208 | 208 | } else if ($c == '.') { |
209 | 209 | $this->state = self::DOT_STATE; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | break; |
214 | 214 | case self::DOT_STATE: |
215 | 215 | $this->currentLiteral .= $c; |
216 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
216 | + if (ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
217 | 217 | $this->formattingInfo->max = ord($c) - ord('0'); |
218 | 218 | $this->state = self::MAX_STATE; |
219 | 219 | } else { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | break; |
223 | 223 | case self::MAX_STATE: |
224 | 224 | $this->currentLiteral .= $c; |
225 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
225 | + if (ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
226 | 226 | $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0')); |
227 | 227 | } else { |
228 | 228 | $this->finalizeConverter($c); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | break; |
232 | 232 | } // switch |
233 | 233 | } // while |
234 | - if(strlen($this->currentLiteral) != 0) { |
|
234 | + if (strlen($this->currentLiteral) != 0) { |
|
235 | 235 | $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
236 | 236 | } |
237 | 237 | return $this->head; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | |
240 | 240 | public function finalizeConverter($c) { |
241 | 241 | $pc = null; |
242 | - switch($c) { |
|
242 | + switch ($c) { |
|
243 | 243 | case 'c': |
244 | 244 | $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
245 | 245 | $this->currentLiteral = ''; |
@@ -252,18 +252,18 @@ discard block |
||
252 | 252 | $dateFormatStr = self::DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT; |
253 | 253 | $dOpt = $this->extractOption(); |
254 | 254 | |
255 | - if($dOpt !== null) |
|
255 | + if ($dOpt !== null) |
|
256 | 256 | $dateFormatStr = $dOpt; |
257 | 257 | |
258 | - if($dateFormatStr == 'ISO8601') { |
|
258 | + if ($dateFormatStr == 'ISO8601') { |
|
259 | 259 | $df = self::DATE_FORMAT_ISO8601; |
260 | - } else if($dateFormatStr == 'ABSOLUTE') { |
|
260 | + } else if ($dateFormatStr == 'ABSOLUTE') { |
|
261 | 261 | $df = self::DATE_FORMAT_ABSOLUTE; |
262 | - } else if($dateFormatStr == 'DATE') { |
|
262 | + } else if ($dateFormatStr == 'DATE') { |
|
263 | 263 | $df = self::DATE_FORMAT_DATE; |
264 | 264 | } else { |
265 | 265 | $df = $dateFormatStr; |
266 | - if($df == null) { |
|
266 | + if ($df == null) { |
|
267 | 267 | $df = self::DATE_FORMAT_ISO8601; |
268 | 268 | } |
269 | 269 | } |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | $this->currentLiteral = ''; |
304 | 304 | break; |
305 | 305 | case 'u': |
306 | - if($this->i < $this->patternLength) { |
|
306 | + if ($this->i < $this->patternLength) { |
|
307 | 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'))); |
|
308 | + if (ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) { |
|
309 | + $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string) (ord($cNext) - ord('0'))); |
|
310 | 310 | $this->currentLiteral = ''; |
311 | 311 | $this->i++; |
312 | 312 | } |
@@ -252,8 +252,9 @@ |
||
252 | 252 | $dateFormatStr = self::DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT; |
253 | 253 | $dOpt = $this->extractOption(); |
254 | 254 | |
255 | - if($dOpt !== null) |
|
256 | - $dateFormatStr = $dOpt; |
|
255 | + if($dOpt !== null) { |
|
256 | + $dateFormatStr = $dOpt; |
|
257 | + } |
|
257 | 258 | |
258 | 259 | if($dateFormatStr == 'ISO8601') { |
259 | 260 | $df = self::DATE_FORMAT_ISO8601; |
@@ -33,309 +33,309 @@ |
||
33 | 33 | */ |
34 | 34 | class LoggerPatternParser { |
35 | 35 | |
36 | - const ESCAPE_CHAR = '%'; |
|
36 | + const ESCAPE_CHAR = '%'; |
|
37 | 37 | |
38 | - const LITERAL_STATE = 0; |
|
39 | - const CONVERTER_STATE = 1; |
|
40 | - const MINUS_STATE = 2; |
|
41 | - const DOT_STATE = 3; |
|
42 | - const MIN_STATE = 4; |
|
43 | - const MAX_STATE = 5; |
|
38 | + const LITERAL_STATE = 0; |
|
39 | + const CONVERTER_STATE = 1; |
|
40 | + const MINUS_STATE = 2; |
|
41 | + const DOT_STATE = 3; |
|
42 | + const MIN_STATE = 4; |
|
43 | + const MAX_STATE = 5; |
|
44 | 44 | |
45 | - const FULL_LOCATION_CONVERTER = 1000; |
|
46 | - const METHOD_LOCATION_CONVERTER = 1001; |
|
47 | - const CLASS_LOCATION_CONVERTER = 1002; |
|
48 | - const FILE_LOCATION_CONVERTER = 1003; |
|
49 | - const LINE_LOCATION_CONVERTER = 1004; |
|
45 | + const FULL_LOCATION_CONVERTER = 1000; |
|
46 | + const METHOD_LOCATION_CONVERTER = 1001; |
|
47 | + const CLASS_LOCATION_CONVERTER = 1002; |
|
48 | + const FILE_LOCATION_CONVERTER = 1003; |
|
49 | + const LINE_LOCATION_CONVERTER = 1004; |
|
50 | 50 | |
51 | - const RELATIVE_TIME_CONVERTER = 2000; |
|
52 | - const THREAD_CONVERTER = 2001; |
|
53 | - const LEVEL_CONVERTER = 2002; |
|
54 | - const NDC_CONVERTER = 2003; |
|
55 | - const MESSAGE_CONVERTER = 2004; |
|
51 | + const RELATIVE_TIME_CONVERTER = 2000; |
|
52 | + const THREAD_CONVERTER = 2001; |
|
53 | + const LEVEL_CONVERTER = 2002; |
|
54 | + const NDC_CONVERTER = 2003; |
|
55 | + const MESSAGE_CONVERTER = 2004; |
|
56 | 56 | |
57 | - const DATE_FORMAT_ISO8601 = 'Y-m-d H:i:s,u'; |
|
58 | - const DATE_FORMAT_ABSOLUTE = 'H:i:s'; |
|
59 | - const DATE_FORMAT_DATE = 'd M Y H:i:s,u'; |
|
57 | + const DATE_FORMAT_ISO8601 = 'Y-m-d H:i:s,u'; |
|
58 | + const DATE_FORMAT_ABSOLUTE = 'H:i:s'; |
|
59 | + const DATE_FORMAT_DATE = 'd M Y H:i:s,u'; |
|
60 | 60 | |
61 | - private $state; |
|
62 | - private $currentLiteral; |
|
63 | - private $patternLength; |
|
64 | - private $i; |
|
61 | + private $state; |
|
62 | + private $currentLiteral; |
|
63 | + private $patternLength; |
|
64 | + private $i; |
|
65 | 65 | |
66 | - /** |
|
67 | - * @var LoggerPatternConverter |
|
68 | - */ |
|
69 | - private $head = null; |
|
66 | + /** |
|
67 | + * @var LoggerPatternConverter |
|
68 | + */ |
|
69 | + private $head = null; |
|
70 | 70 | |
71 | - /** |
|
72 | - * @var LoggerPatternConverter |
|
73 | - */ |
|
74 | - private $tail = null; |
|
71 | + /** |
|
72 | + * @var LoggerPatternConverter |
|
73 | + */ |
|
74 | + private $tail = null; |
|
75 | 75 | |
76 | - /** |
|
77 | - * @var LoggerFormattingInfo |
|
78 | - */ |
|
79 | - private $formattingInfo; |
|
76 | + /** |
|
77 | + * @var LoggerFormattingInfo |
|
78 | + */ |
|
79 | + private $formattingInfo; |
|
80 | 80 | |
81 | - /** |
|
82 | - * @var string pattern to parse |
|
83 | - */ |
|
84 | - private $pattern; |
|
81 | + /** |
|
82 | + * @var string pattern to parse |
|
83 | + */ |
|
84 | + private $pattern; |
|
85 | 85 | |
86 | - /** |
|
87 | - * Constructor |
|
88 | - * |
|
89 | - * @param string $pattern |
|
90 | - */ |
|
91 | - public function __construct($pattern) { |
|
92 | - $this->pattern = $pattern; |
|
93 | - $this->patternLength = strlen($pattern); |
|
94 | - $this->formattingInfo = new LoggerFormattingInfo(); |
|
95 | - $this->state = self::LITERAL_STATE; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Constructor |
|
88 | + * |
|
89 | + * @param string $pattern |
|
90 | + */ |
|
91 | + public function __construct($pattern) { |
|
92 | + $this->pattern = $pattern; |
|
93 | + $this->patternLength = strlen($pattern); |
|
94 | + $this->formattingInfo = new LoggerFormattingInfo(); |
|
95 | + $this->state = self::LITERAL_STATE; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @param LoggerPatternConverter $pc |
|
100 | - */ |
|
101 | - public function addToList($pc) { |
|
102 | - if($this->head == null) { |
|
103 | - $this->head = $pc; |
|
104 | - $this->tail = $this->head; |
|
105 | - } else { |
|
106 | - $this->tail->next = $pc; |
|
107 | - $this->tail = $this->tail->next; |
|
108 | - } |
|
109 | - } |
|
98 | + /** |
|
99 | + * @param LoggerPatternConverter $pc |
|
100 | + */ |
|
101 | + public function addToList($pc) { |
|
102 | + if($this->head == null) { |
|
103 | + $this->head = $pc; |
|
104 | + $this->tail = $this->head; |
|
105 | + } else { |
|
106 | + $this->tail->next = $pc; |
|
107 | + $this->tail = $this->tail->next; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function extractOption() { |
|
115 | - if(($this->i < $this->patternLength) and ($this->pattern{$this->i} == '{')) { |
|
116 | - $end = strpos($this->pattern, '}' , $this->i); |
|
117 | - if($end !== false) { |
|
118 | - $r = substr($this->pattern, ($this->i + 1), ($end - $this->i - 1)); |
|
119 | - $this->i= $end + 1; |
|
120 | - return $r; |
|
121 | - } |
|
122 | - } |
|
123 | - return null; |
|
124 | - } |
|
111 | + /** |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function extractOption() { |
|
115 | + if(($this->i < $this->patternLength) and ($this->pattern{$this->i} == '{')) { |
|
116 | + $end = strpos($this->pattern, '}' , $this->i); |
|
117 | + if($end !== false) { |
|
118 | + $r = substr($this->pattern, ($this->i + 1), ($end - $this->i - 1)); |
|
119 | + $this->i= $end + 1; |
|
120 | + return $r; |
|
121 | + } |
|
122 | + } |
|
123 | + return null; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * The option is expected to be in decimal and positive. In case of |
|
128 | - * error, zero is returned. |
|
129 | - */ |
|
130 | - public function extractPrecisionOption() { |
|
131 | - $opt = $this->extractOption(); |
|
132 | - $r = 0; |
|
133 | - if($opt !== null) { |
|
134 | - if(is_numeric($opt)) { |
|
135 | - $r = (int)$opt; |
|
136 | - if($r <= 0) { |
|
137 | - $r = 0; |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - return $r; |
|
142 | - } |
|
126 | + /** |
|
127 | + * The option is expected to be in decimal and positive. In case of |
|
128 | + * error, zero is returned. |
|
129 | + */ |
|
130 | + public function extractPrecisionOption() { |
|
131 | + $opt = $this->extractOption(); |
|
132 | + $r = 0; |
|
133 | + if($opt !== null) { |
|
134 | + if(is_numeric($opt)) { |
|
135 | + $r = (int)$opt; |
|
136 | + if($r <= 0) { |
|
137 | + $r = 0; |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + return $r; |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - /** Parser. |
|
146 | - * |
|
147 | - * @return LoggerPatternConverter Returns $this->head. |
|
148 | - */ |
|
149 | - public function parse() { |
|
150 | - $c = ''; |
|
151 | - $this->i = 0; |
|
152 | - $this->currentLiteral = ''; |
|
153 | - while($this->i < $this->patternLength) { |
|
154 | - $c = $this->pattern{$this->i++}; |
|
145 | + /** Parser. |
|
146 | + * |
|
147 | + * @return LoggerPatternConverter Returns $this->head. |
|
148 | + */ |
|
149 | + public function parse() { |
|
150 | + $c = ''; |
|
151 | + $this->i = 0; |
|
152 | + $this->currentLiteral = ''; |
|
153 | + while($this->i < $this->patternLength) { |
|
154 | + $c = $this->pattern{$this->i++}; |
|
155 | 155 | |
156 | - switch($this->state) { |
|
157 | - case self::LITERAL_STATE: |
|
158 | - // In literal state, the last char is always a literal. |
|
159 | - if($this->i == $this->patternLength) { |
|
160 | - $this->currentLiteral .= $c; |
|
161 | - continue; |
|
162 | - } |
|
163 | - if($c == self::ESCAPE_CHAR) { |
|
164 | - // peek at the next char. |
|
165 | - switch($this->pattern{$this->i}) { |
|
166 | - case self::ESCAPE_CHAR: |
|
167 | - $this->currentLiteral .= $c; |
|
168 | - $this->i++; // move pointer |
|
169 | - break; |
|
170 | - case 'n': |
|
171 | - $this->currentLiteral .= PHP_EOL; |
|
172 | - $this->i++; // move pointer |
|
173 | - break; |
|
174 | - default: |
|
175 | - if(strlen($this->currentLiteral) != 0) { |
|
176 | - $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
177 | - } |
|
178 | - $this->currentLiteral = $c; |
|
179 | - $this->state = self::CONVERTER_STATE; |
|
180 | - $this->formattingInfo->reset(); |
|
181 | - } |
|
182 | - } else { |
|
183 | - $this->currentLiteral .= $c; |
|
184 | - } |
|
185 | - break; |
|
186 | - case self::CONVERTER_STATE: |
|
187 | - $this->currentLiteral .= $c; |
|
188 | - switch($c) { |
|
189 | - case '-': |
|
190 | - $this->formattingInfo->leftAlign = true; |
|
191 | - break; |
|
192 | - case '.': |
|
193 | - $this->state = self::DOT_STATE; |
|
194 | - break; |
|
195 | - default: |
|
196 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
197 | - $this->formattingInfo->min = ord($c) - ord('0'); |
|
198 | - $this->state = self::MIN_STATE; |
|
199 | - } else { |
|
200 | - $this->finalizeConverter($c); |
|
201 | - } |
|
202 | - } // switch |
|
203 | - break; |
|
204 | - case self::MIN_STATE: |
|
205 | - $this->currentLiteral .= $c; |
|
206 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
207 | - $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0')); |
|
208 | - } else if ($c == '.') { |
|
209 | - $this->state = self::DOT_STATE; |
|
210 | - } else { |
|
211 | - $this->finalizeConverter($c); |
|
212 | - } |
|
213 | - break; |
|
214 | - case self::DOT_STATE: |
|
215 | - $this->currentLiteral .= $c; |
|
216 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
217 | - $this->formattingInfo->max = ord($c) - ord('0'); |
|
218 | - $this->state = self::MAX_STATE; |
|
219 | - } else { |
|
220 | - $this->state = self::LITERAL_STATE; |
|
221 | - } |
|
222 | - break; |
|
223 | - case self::MAX_STATE: |
|
224 | - $this->currentLiteral .= $c; |
|
225 | - if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
226 | - $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0')); |
|
227 | - } else { |
|
228 | - $this->finalizeConverter($c); |
|
229 | - $this->state = self::LITERAL_STATE; |
|
230 | - } |
|
231 | - break; |
|
232 | - } // switch |
|
233 | - } // while |
|
234 | - if(strlen($this->currentLiteral) != 0) { |
|
235 | - $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
236 | - } |
|
237 | - return $this->head; |
|
238 | - } |
|
156 | + switch($this->state) { |
|
157 | + case self::LITERAL_STATE: |
|
158 | + // In literal state, the last char is always a literal. |
|
159 | + if($this->i == $this->patternLength) { |
|
160 | + $this->currentLiteral .= $c; |
|
161 | + continue; |
|
162 | + } |
|
163 | + if($c == self::ESCAPE_CHAR) { |
|
164 | + // peek at the next char. |
|
165 | + switch($this->pattern{$this->i}) { |
|
166 | + case self::ESCAPE_CHAR: |
|
167 | + $this->currentLiteral .= $c; |
|
168 | + $this->i++; // move pointer |
|
169 | + break; |
|
170 | + case 'n': |
|
171 | + $this->currentLiteral .= PHP_EOL; |
|
172 | + $this->i++; // move pointer |
|
173 | + break; |
|
174 | + default: |
|
175 | + if(strlen($this->currentLiteral) != 0) { |
|
176 | + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
177 | + } |
|
178 | + $this->currentLiteral = $c; |
|
179 | + $this->state = self::CONVERTER_STATE; |
|
180 | + $this->formattingInfo->reset(); |
|
181 | + } |
|
182 | + } else { |
|
183 | + $this->currentLiteral .= $c; |
|
184 | + } |
|
185 | + break; |
|
186 | + case self::CONVERTER_STATE: |
|
187 | + $this->currentLiteral .= $c; |
|
188 | + switch($c) { |
|
189 | + case '-': |
|
190 | + $this->formattingInfo->leftAlign = true; |
|
191 | + break; |
|
192 | + case '.': |
|
193 | + $this->state = self::DOT_STATE; |
|
194 | + break; |
|
195 | + default: |
|
196 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
197 | + $this->formattingInfo->min = ord($c) - ord('0'); |
|
198 | + $this->state = self::MIN_STATE; |
|
199 | + } else { |
|
200 | + $this->finalizeConverter($c); |
|
201 | + } |
|
202 | + } // switch |
|
203 | + break; |
|
204 | + case self::MIN_STATE: |
|
205 | + $this->currentLiteral .= $c; |
|
206 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
207 | + $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0')); |
|
208 | + } else if ($c == '.') { |
|
209 | + $this->state = self::DOT_STATE; |
|
210 | + } else { |
|
211 | + $this->finalizeConverter($c); |
|
212 | + } |
|
213 | + break; |
|
214 | + case self::DOT_STATE: |
|
215 | + $this->currentLiteral .= $c; |
|
216 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
217 | + $this->formattingInfo->max = ord($c) - ord('0'); |
|
218 | + $this->state = self::MAX_STATE; |
|
219 | + } else { |
|
220 | + $this->state = self::LITERAL_STATE; |
|
221 | + } |
|
222 | + break; |
|
223 | + case self::MAX_STATE: |
|
224 | + $this->currentLiteral .= $c; |
|
225 | + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { |
|
226 | + $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0')); |
|
227 | + } else { |
|
228 | + $this->finalizeConverter($c); |
|
229 | + $this->state = self::LITERAL_STATE; |
|
230 | + } |
|
231 | + break; |
|
232 | + } // switch |
|
233 | + } // while |
|
234 | + if(strlen($this->currentLiteral) != 0) { |
|
235 | + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); |
|
236 | + } |
|
237 | + return $this->head; |
|
238 | + } |
|
239 | 239 | |
240 | - public function finalizeConverter($c) { |
|
241 | - $pc = null; |
|
242 | - switch($c) { |
|
243 | - case 'c': |
|
244 | - $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
245 | - $this->currentLiteral = ''; |
|
246 | - break; |
|
247 | - case 'C': |
|
248 | - $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
249 | - $this->currentLiteral = ''; |
|
250 | - break; |
|
251 | - case 'd': |
|
252 | - $dateFormatStr = self::DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT; |
|
253 | - $dOpt = $this->extractOption(); |
|
240 | + public function finalizeConverter($c) { |
|
241 | + $pc = null; |
|
242 | + switch($c) { |
|
243 | + case 'c': |
|
244 | + $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
245 | + $this->currentLiteral = ''; |
|
246 | + break; |
|
247 | + case 'C': |
|
248 | + $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption()); |
|
249 | + $this->currentLiteral = ''; |
|
250 | + break; |
|
251 | + case 'd': |
|
252 | + $dateFormatStr = self::DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT; |
|
253 | + $dOpt = $this->extractOption(); |
|
254 | 254 | |
255 | - if($dOpt !== null) |
|
256 | - $dateFormatStr = $dOpt; |
|
255 | + if($dOpt !== null) |
|
256 | + $dateFormatStr = $dOpt; |
|
257 | 257 | |
258 | - if($dateFormatStr == 'ISO8601') { |
|
259 | - $df = self::DATE_FORMAT_ISO8601; |
|
260 | - } else if($dateFormatStr == 'ABSOLUTE') { |
|
261 | - $df = self::DATE_FORMAT_ABSOLUTE; |
|
262 | - } else if($dateFormatStr == 'DATE') { |
|
263 | - $df = self::DATE_FORMAT_DATE; |
|
264 | - } else { |
|
265 | - $df = $dateFormatStr; |
|
266 | - if($df == null) { |
|
267 | - $df = self::DATE_FORMAT_ISO8601; |
|
268 | - } |
|
269 | - } |
|
270 | - $pc = new LoggerDatePatternConverter($this->formattingInfo, $df); |
|
271 | - $this->currentLiteral = ''; |
|
272 | - break; |
|
273 | - case 'F': |
|
274 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FILE_LOCATION_CONVERTER); |
|
275 | - $this->currentLiteral = ''; |
|
276 | - break; |
|
277 | - case 'l': |
|
278 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FULL_LOCATION_CONVERTER); |
|
279 | - $this->currentLiteral = ''; |
|
280 | - break; |
|
281 | - case 'L': |
|
282 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::LINE_LOCATION_CONVERTER); |
|
283 | - $this->currentLiteral = ''; |
|
284 | - break; |
|
285 | - case 'm': |
|
286 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::MESSAGE_CONVERTER); |
|
287 | - $this->currentLiteral = ''; |
|
288 | - break; |
|
289 | - case 'M': |
|
290 | - $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::METHOD_LOCATION_CONVERTER); |
|
291 | - $this->currentLiteral = ''; |
|
292 | - break; |
|
293 | - case 'p': |
|
294 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::LEVEL_CONVERTER); |
|
295 | - $this->currentLiteral = ''; |
|
296 | - break; |
|
297 | - case 'r': |
|
298 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::RELATIVE_TIME_CONVERTER); |
|
299 | - $this->currentLiteral = ''; |
|
300 | - break; |
|
301 | - case 't': |
|
302 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::THREAD_CONVERTER); |
|
303 | - $this->currentLiteral = ''; |
|
304 | - break; |
|
305 | - case 'u': |
|
306 | - if($this->i < $this->patternLength) { |
|
307 | - $cNext = $this->pattern{$this->i}; |
|
308 | - if(ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) { |
|
309 | - $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string)(ord($cNext) - ord('0'))); |
|
310 | - $this->currentLiteral = ''; |
|
311 | - $this->i++; |
|
312 | - } |
|
313 | - } |
|
314 | - break; |
|
315 | - case 'x': |
|
316 | - $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::NDC_CONVERTER); |
|
317 | - $this->currentLiteral = ''; |
|
318 | - break; |
|
319 | - case 'X': |
|
320 | - $xOpt = $this->extractOption(); |
|
321 | - $pc = new LoggerMDCPatternConverter($this->formattingInfo, $xOpt); |
|
322 | - $this->currentLiteral = ''; |
|
323 | - break; |
|
324 | - default: |
|
325 | - $pc = new LoggerLiteralPatternConverter($this->currentLiteral); |
|
326 | - $this->currentLiteral = ''; |
|
327 | - } |
|
328 | - $this->addConverter($pc); |
|
329 | - } |
|
258 | + if($dateFormatStr == 'ISO8601') { |
|
259 | + $df = self::DATE_FORMAT_ISO8601; |
|
260 | + } else if($dateFormatStr == 'ABSOLUTE') { |
|
261 | + $df = self::DATE_FORMAT_ABSOLUTE; |
|
262 | + } else if($dateFormatStr == 'DATE') { |
|
263 | + $df = self::DATE_FORMAT_DATE; |
|
264 | + } else { |
|
265 | + $df = $dateFormatStr; |
|
266 | + if($df == null) { |
|
267 | + $df = self::DATE_FORMAT_ISO8601; |
|
268 | + } |
|
269 | + } |
|
270 | + $pc = new LoggerDatePatternConverter($this->formattingInfo, $df); |
|
271 | + $this->currentLiteral = ''; |
|
272 | + break; |
|
273 | + case 'F': |
|
274 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FILE_LOCATION_CONVERTER); |
|
275 | + $this->currentLiteral = ''; |
|
276 | + break; |
|
277 | + case 'l': |
|
278 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::FULL_LOCATION_CONVERTER); |
|
279 | + $this->currentLiteral = ''; |
|
280 | + break; |
|
281 | + case 'L': |
|
282 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::LINE_LOCATION_CONVERTER); |
|
283 | + $this->currentLiteral = ''; |
|
284 | + break; |
|
285 | + case 'm': |
|
286 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::MESSAGE_CONVERTER); |
|
287 | + $this->currentLiteral = ''; |
|
288 | + break; |
|
289 | + case 'M': |
|
290 | + $pc = new LoggerLocationPatternConverter($this->formattingInfo, self::METHOD_LOCATION_CONVERTER); |
|
291 | + $this->currentLiteral = ''; |
|
292 | + break; |
|
293 | + case 'p': |
|
294 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::LEVEL_CONVERTER); |
|
295 | + $this->currentLiteral = ''; |
|
296 | + break; |
|
297 | + case 'r': |
|
298 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::RELATIVE_TIME_CONVERTER); |
|
299 | + $this->currentLiteral = ''; |
|
300 | + break; |
|
301 | + case 't': |
|
302 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::THREAD_CONVERTER); |
|
303 | + $this->currentLiteral = ''; |
|
304 | + break; |
|
305 | + case 'u': |
|
306 | + if($this->i < $this->patternLength) { |
|
307 | + $cNext = $this->pattern{$this->i}; |
|
308 | + if(ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) { |
|
309 | + $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string)(ord($cNext) - ord('0'))); |
|
310 | + $this->currentLiteral = ''; |
|
311 | + $this->i++; |
|
312 | + } |
|
313 | + } |
|
314 | + break; |
|
315 | + case 'x': |
|
316 | + $pc = new LoggerBasicPatternConverter($this->formattingInfo, self::NDC_CONVERTER); |
|
317 | + $this->currentLiteral = ''; |
|
318 | + break; |
|
319 | + case 'X': |
|
320 | + $xOpt = $this->extractOption(); |
|
321 | + $pc = new LoggerMDCPatternConverter($this->formattingInfo, $xOpt); |
|
322 | + $this->currentLiteral = ''; |
|
323 | + break; |
|
324 | + default: |
|
325 | + $pc = new LoggerLiteralPatternConverter($this->currentLiteral); |
|
326 | + $this->currentLiteral = ''; |
|
327 | + } |
|
328 | + $this->addConverter($pc); |
|
329 | + } |
|
330 | 330 | |
331 | - public function addConverter($pc) { |
|
332 | - $this->currentLiteral = ''; |
|
333 | - // Add the pattern converter to the list. |
|
334 | - $this->addToList($pc); |
|
335 | - // Next pattern is assumed to be a literal. |
|
336 | - $this->state = self::LITERAL_STATE; |
|
337 | - // Reset formatting info |
|
338 | - $this->formattingInfo->reset(); |
|
339 | - } |
|
331 | + public function addConverter($pc) { |
|
332 | + $this->currentLiteral = ''; |
|
333 | + // Add the pattern converter to the list. |
|
334 | + $this->addToList($pc); |
|
335 | + // Next pattern is assumed to be a literal. |
|
336 | + $this->state = self::LITERAL_STATE; |
|
337 | + // Reset formatting info |
|
338 | + $this->formattingInfo->reset(); |
|
339 | + } |
|
340 | 340 | } |
341 | 341 |
@@ -169,6 +169,7 @@ |
||
169 | 169 | * Set the <b>ConversionPattern</b> option. This is the string which |
170 | 170 | * controls formatting and consists of a mix of literal content and |
171 | 171 | * conversion specifiers. |
172 | + * @param string $conversionPattern |
|
172 | 173 | */ |
173 | 174 | public function setConversionPattern($conversionPattern) { |
174 | 175 | $this->pattern = $conversionPattern; |
@@ -206,7 +206,7 @@ |
||
206 | 206 | $results = array(); |
207 | 207 | $c = $this->head; |
208 | 208 | while ($c !== null) { |
209 | - if ( ! $c instanceOf LoggerLiteralPatternConverter) { |
|
209 | + if (!$c instanceOf LoggerLiteralPatternConverter) { |
|
210 | 210 | $sbuf = null; |
211 | 211 | $c->format($sbuf, $event); |
212 | 212 | $results[] = $sbuf; |
@@ -136,61 +136,61 @@ |
||
136 | 136 | * @since 0.3 |
137 | 137 | */ |
138 | 138 | class LoggerLayoutPattern extends LoggerLayout { |
139 | - /** Default conversion Pattern */ |
|
140 | - const DEFAULT_CONVERSION_PATTERN = '%m%n'; |
|
139 | + /** Default conversion Pattern */ |
|
140 | + const DEFAULT_CONVERSION_PATTERN = '%m%n'; |
|
141 | 141 | |
142 | - /** Default conversion TTCC Pattern */ |
|
143 | - const TTCC_CONVERSION_PATTERN = '%r [%t] %p %c %x - %m%n'; |
|
142 | + /** Default conversion TTCC Pattern */ |
|
143 | + const TTCC_CONVERSION_PATTERN = '%r [%t] %p %c %x - %m%n'; |
|
144 | 144 | |
145 | - /** The pattern. |
|
146 | - * @var string */ |
|
147 | - private $pattern; |
|
145 | + /** The pattern. |
|
146 | + * @var string */ |
|
147 | + private $pattern; |
|
148 | 148 | |
149 | - /** Head of a chain of Converters. |
|
150 | - * @var LoggerPatternConverter */ |
|
151 | - private $head; |
|
149 | + /** Head of a chain of Converters. |
|
150 | + * @var LoggerPatternConverter */ |
|
151 | + private $head; |
|
152 | 152 | |
153 | - private $timezone; |
|
153 | + private $timezone; |
|
154 | 154 | |
155 | - /** |
|
156 | - * Constructs a PatternLayout using the |
|
157 | - * {@link DEFAULT_LAYOUT_PATTERN}. |
|
158 | - * The default pattern just produces the application supplied message. |
|
159 | - */ |
|
160 | - public function __construct($pattern = null) { |
|
161 | - if ($pattern === null) { |
|
162 | - $this->pattern = self :: DEFAULT_CONVERSION_PATTERN; |
|
163 | - } else { |
|
164 | - $this->pattern = $pattern; |
|
165 | - } |
|
166 | - } |
|
155 | + /** |
|
156 | + * Constructs a PatternLayout using the |
|
157 | + * {@link DEFAULT_LAYOUT_PATTERN}. |
|
158 | + * The default pattern just produces the application supplied message. |
|
159 | + */ |
|
160 | + public function __construct($pattern = null) { |
|
161 | + if ($pattern === null) { |
|
162 | + $this->pattern = self :: DEFAULT_CONVERSION_PATTERN; |
|
163 | + } else { |
|
164 | + $this->pattern = $pattern; |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Set the <b>ConversionPattern</b> option. This is the string which |
|
170 | - * controls formatting and consists of a mix of literal content and |
|
171 | - * conversion specifiers. |
|
172 | - */ |
|
173 | - public function setConversionPattern($conversionPattern) { |
|
174 | - $this->pattern = $conversionPattern; |
|
175 | - $patternParser = new LoggerPatternParser($this->pattern); |
|
176 | - $this->head = $patternParser->parse(); |
|
177 | - } |
|
168 | + /** |
|
169 | + * Set the <b>ConversionPattern</b> option. This is the string which |
|
170 | + * controls formatting and consists of a mix of literal content and |
|
171 | + * conversion specifiers. |
|
172 | + */ |
|
173 | + public function setConversionPattern($conversionPattern) { |
|
174 | + $this->pattern = $conversionPattern; |
|
175 | + $patternParser = new LoggerPatternParser($this->pattern); |
|
176 | + $this->head = $patternParser->parse(); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Produces a formatted string as specified by the conversion pattern. |
|
181 | - * |
|
182 | - * @param LoggerLoggingEvent $event |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function format(LoggerLoggingEvent $event) { |
|
186 | - $sbuf = ''; |
|
187 | - $c = $this->head; |
|
188 | - while ($c !== null) { |
|
189 | - $c->format($sbuf, $event); |
|
190 | - $c = $c->next; |
|
191 | - } |
|
192 | - return $sbuf; |
|
193 | - } |
|
179 | + /** |
|
180 | + * Produces a formatted string as specified by the conversion pattern. |
|
181 | + * |
|
182 | + * @param LoggerLoggingEvent $event |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function format(LoggerLoggingEvent $event) { |
|
186 | + $sbuf = ''; |
|
187 | + $c = $this->head; |
|
188 | + while ($c !== null) { |
|
189 | + $c->format($sbuf, $event); |
|
190 | + $c = $c->next; |
|
191 | + } |
|
192 | + return $sbuf; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | /** |
196 | 196 | * Returns an array with the formatted elements. |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | /** |
241 | 241 | * Log a message object with the ERROR level including the caller. |
242 | 242 | * |
243 | - * @param mixed $message message |
|
243 | + * @param string $message message |
|
244 | 244 | * @param mixed $caller caller object or caller string id |
245 | 245 | */ |
246 | 246 | public function error($message, $caller = null) { |
@@ -286,6 +286,7 @@ discard block |
||
286 | 286 | * Check whether this category is enabled for a given Level passed as parameter. |
287 | 287 | * |
288 | 288 | * @param LoggerLevel level |
289 | + * @param LoggerLevel $level |
|
289 | 290 | * @return boolean |
290 | 291 | */ |
291 | 292 | public function isEnabledFor($level) { |
@@ -326,6 +327,9 @@ discard block |
||
326 | 327 | } |
327 | 328 | } |
328 | 329 | |
330 | + /** |
|
331 | + * @param LoggerLevel $level |
|
332 | + */ |
|
329 | 333 | private function logLevel($message, $level, $caller = null) { |
330 | 334 | if($level->isGreaterOrEqual($this->getEffectiveLevel())) { |
331 | 335 | $this->forcedLog($this->fqcn, $caller, $level, $message); |
@@ -338,7 +342,6 @@ discard block |
||
338 | 342 | * Get a Logger by name (Delegate to {@link Logger}) |
339 | 343 | * |
340 | 344 | * @param string $name logger name |
341 | - * @param LoggerFactory $factory a {@link LoggerFactory} instance or null |
|
342 | 345 | * @return Logger |
343 | 346 | * @static |
344 | 347 | */ |
@@ -474,7 +477,7 @@ discard block |
||
474 | 477 | * Clears all logger definitions |
475 | 478 | * |
476 | 479 | * @static |
477 | - * @return boolean |
|
480 | + * @return boolean|null |
|
478 | 481 | */ |
479 | 482 | public static function clear() { |
480 | 483 | return self::getHierarchy()->clear(); |
@@ -484,7 +487,7 @@ discard block |
||
484 | 487 | * Destroy configurations for logger definitions |
485 | 488 | * |
486 | 489 | * @static |
487 | - * @return boolean |
|
490 | + * @return boolean|null |
|
488 | 491 | */ |
489 | 492 | public static function resetConfiguration() { |
490 | 493 | $result = self::getHierarchy()->resetConfiguration(); |
@@ -592,7 +595,7 @@ discard block |
||
592 | 595 | |
593 | 596 | /** |
594 | 597 | * Returns the current configurator |
595 | - * @return the configurator |
|
598 | + * @return string configurator |
|
596 | 599 | */ |
597 | 600 | public static function getConfigurationClass() { |
598 | 601 | return self::$configurationClass; |
@@ -600,7 +603,7 @@ discard block |
||
600 | 603 | |
601 | 604 | /** |
602 | 605 | * Returns the current configuration file |
603 | - * @return the configuration file |
|
606 | + * @return null|string configuration file |
|
604 | 607 | */ |
605 | 608 | public static function getConfigurationFile() { |
606 | 609 | return self::$configurationFile; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @version SVN: $Id: Logger.php 824193 2009-10-11 22:51:24Z chammers $ |
44 | 44 | * @link http://logging.apache.org/log4php |
45 | 45 | */ |
46 | - /* |
|
46 | + /* |
|
47 | 47 | * TODO: |
48 | 48 | * Localization: setResourceBundle($bundle) : not supported |
49 | 49 | * Localization: getResourceBundle: not supported |
@@ -51,576 +51,576 @@ discard block |
||
51 | 51 | * Localization: l7dlog($priority, $key, $params, $t) : not supported |
52 | 52 | */ |
53 | 53 | class Logger { |
54 | - private static $_classes = array( |
|
55 | - 'LoggerException' => '/LoggerException.php', |
|
56 | - 'LoggerHierarchy' => '/LoggerHierarchy.php', |
|
57 | - 'LoggerLayout' => '/LoggerLayout.php', |
|
58 | - 'LoggerLevel' => '/LoggerLevel.php', |
|
59 | - 'LoggerMDC' => '/LoggerMDC.php', |
|
60 | - 'LoggerNDC' => '/LoggerNDC.php', |
|
61 | - 'LoggerReflectionUtils' => '/LoggerReflectionUtils.php', |
|
62 | - 'LoggerConfigurator' => '/LoggerConfigurator.php', |
|
63 | - 'LoggerConfiguratorBasic' => '/configurators/LoggerConfiguratorBasic.php', |
|
64 | - 'LoggerConfiguratorIni' => '/configurators/LoggerConfiguratorIni.php', |
|
65 | - 'LoggerConfiguratorPhp' => '/configurators/LoggerConfiguratorPhp.php', |
|
66 | - 'LoggerConfiguratorXml' => '/configurators/LoggerConfiguratorXml.php', |
|
67 | - 'LoggerRoot' => '/LoggerRoot.php', |
|
68 | - 'LoggerAppender' => '/LoggerAppender.php', |
|
69 | - 'LoggerAppenderPool' => '/LoggerAppenderPool.php', |
|
70 | - 'LoggerAppenderAdodb' => '/appenders/LoggerAppenderAdodb.php', |
|
71 | - 'LoggerAppenderPDO' => '/appenders/LoggerAppenderPDO.php', |
|
72 | - 'LoggerAppenderConsole' => '/appenders/LoggerAppenderConsole.php', |
|
73 | - 'LoggerAppenderDailyFile' => '/appenders/LoggerAppenderDailyFile.php', |
|
74 | - 'LoggerAppenderEcho' => '/appenders/LoggerAppenderEcho.php', |
|
75 | - 'LoggerAppenderFile' => '/appenders/LoggerAppenderFile.php', |
|
76 | - 'LoggerAppenderMail' => '/appenders/LoggerAppenderMail.php', |
|
77 | - 'LoggerAppenderMailEvent' => '/appenders/LoggerAppenderMailEvent.php', |
|
78 | - 'LoggerAppenderNull' => '/appenders/LoggerAppenderNull.php', |
|
79 | - 'LoggerAppenderPhp' => '/appenders/LoggerAppenderPhp.php', |
|
80 | - 'LoggerAppenderRollingFile' => '/appenders/LoggerAppenderRollingFile.php', |
|
81 | - 'LoggerAppenderSocket' => '/appenders/LoggerAppenderSocket.php', |
|
82 | - 'LoggerAppenderSyslog' => '/appenders/LoggerAppenderSyslog.php', |
|
83 | - 'LoggerFormattingInfo' => '/helpers/LoggerFormattingInfo.php', |
|
84 | - 'LoggerOptionConverter' => '/helpers/LoggerOptionConverter.php', |
|
85 | - 'LoggerPatternConverter' => '/helpers/LoggerPatternConverter.php', |
|
86 | - 'LoggerBasicPatternConverter' => '/helpers/LoggerBasicPatternConverter.php', |
|
87 | - 'LoggerCategoryPatternConverter' => '/helpers/LoggerCategoryPatternConverter.php', |
|
88 | - 'LoggerClassNamePatternConverter' => '/helpers/LoggerClassNamePatternConverter.php', |
|
89 | - 'LoggerDatePatternConverter' => '/helpers/LoggerDatePatternConverter.php', |
|
90 | - 'LoggerLiteralPatternConverter' => '/helpers/LoggerLiteralPatternConverter.php', |
|
91 | - 'LoggerLocationPatternConverter' => '/helpers/LoggerLocationPatternConverter.php', |
|
92 | - 'LoggerMDCPatternConverter' => '/helpers/LoggerMDCPatternConverter.php', |
|
93 | - 'LoggerNamedPatternConverter' => '/helpers/LoggerNamedPatternConverter.php', |
|
94 | - 'LoggerBasicPatternConverter' => '/helpers/LoggerBasicPatternConverter.php', |
|
95 | - 'LoggerLiteralPatternConverter' => '/helpers/LoggerLiteralPatternConverter.php', |
|
96 | - 'LoggerDatePatternConverter' => '/helpers/LoggerDatePatternConverter.php', |
|
97 | - 'LoggerMDCPatternConverter' => '/helpers/LoggerMDCPatternConverter.php', |
|
98 | - 'LoggerLocationPatternConverter' => '/helpers/LoggerLocationPatternConverter.php', |
|
99 | - 'LoggerNamedPatternConverter' => '/helpers/LoggerNamedPatternConverter.php', |
|
100 | - 'LoggerClassNamePatternConverter' => '/helpers/LoggerClassNamePatternConverter.php', |
|
101 | - 'LoggerCategoryPatternConverter' => '/helpers/LoggerCategoryPatternConverter.php', |
|
102 | - 'LoggerPatternParser' => '/helpers/LoggerPatternParser.php', |
|
103 | - 'LoggerLayoutHtml' => '/layouts/LoggerLayoutHtml.php', |
|
104 | - 'LoggerLayoutSimple' => '/layouts/LoggerLayoutSimple.php', |
|
105 | - 'LoggerLayoutTTCC' => '/layouts/LoggerLayoutTTCC.php', |
|
106 | - 'LoggerLayoutPattern' => '/layouts/LoggerLayoutPattern.php', |
|
107 | - 'LoggerLayoutXml' => '/layouts/LoggerLayoutXml.php', |
|
108 | - 'LoggerRendererDefault' => '/renderers/LoggerRendererDefault.php', |
|
109 | - 'LoggerRendererObject' => '/renderers/LoggerRendererObject.php', |
|
110 | - 'LoggerRendererMap' => '/renderers/LoggerRendererMap.php', |
|
111 | - 'LoggerLocationInfo' => '/LoggerLocationInfo.php', |
|
112 | - 'LoggerLoggingEvent' => '/LoggerLoggingEvent.php', |
|
113 | - 'LoggerFilter' => '/LoggerFilter.php', |
|
114 | - 'LoggerFilterDenyAll' => '/filters/LoggerFilterDenyAll.php', |
|
115 | - 'LoggerFilterLevelMatch' => '/filters/LoggerFilterLevelMatch.php', |
|
116 | - 'LoggerFilterLevelRange' => '/filters/LoggerFilterLevelRange.php', |
|
117 | - 'LoggerFilterStringMatch' => '/filters/LoggerFilterStringMatch.php', |
|
118 | - ); |
|
54 | + private static $_classes = array( |
|
55 | + 'LoggerException' => '/LoggerException.php', |
|
56 | + 'LoggerHierarchy' => '/LoggerHierarchy.php', |
|
57 | + 'LoggerLayout' => '/LoggerLayout.php', |
|
58 | + 'LoggerLevel' => '/LoggerLevel.php', |
|
59 | + 'LoggerMDC' => '/LoggerMDC.php', |
|
60 | + 'LoggerNDC' => '/LoggerNDC.php', |
|
61 | + 'LoggerReflectionUtils' => '/LoggerReflectionUtils.php', |
|
62 | + 'LoggerConfigurator' => '/LoggerConfigurator.php', |
|
63 | + 'LoggerConfiguratorBasic' => '/configurators/LoggerConfiguratorBasic.php', |
|
64 | + 'LoggerConfiguratorIni' => '/configurators/LoggerConfiguratorIni.php', |
|
65 | + 'LoggerConfiguratorPhp' => '/configurators/LoggerConfiguratorPhp.php', |
|
66 | + 'LoggerConfiguratorXml' => '/configurators/LoggerConfiguratorXml.php', |
|
67 | + 'LoggerRoot' => '/LoggerRoot.php', |
|
68 | + 'LoggerAppender' => '/LoggerAppender.php', |
|
69 | + 'LoggerAppenderPool' => '/LoggerAppenderPool.php', |
|
70 | + 'LoggerAppenderAdodb' => '/appenders/LoggerAppenderAdodb.php', |
|
71 | + 'LoggerAppenderPDO' => '/appenders/LoggerAppenderPDO.php', |
|
72 | + 'LoggerAppenderConsole' => '/appenders/LoggerAppenderConsole.php', |
|
73 | + 'LoggerAppenderDailyFile' => '/appenders/LoggerAppenderDailyFile.php', |
|
74 | + 'LoggerAppenderEcho' => '/appenders/LoggerAppenderEcho.php', |
|
75 | + 'LoggerAppenderFile' => '/appenders/LoggerAppenderFile.php', |
|
76 | + 'LoggerAppenderMail' => '/appenders/LoggerAppenderMail.php', |
|
77 | + 'LoggerAppenderMailEvent' => '/appenders/LoggerAppenderMailEvent.php', |
|
78 | + 'LoggerAppenderNull' => '/appenders/LoggerAppenderNull.php', |
|
79 | + 'LoggerAppenderPhp' => '/appenders/LoggerAppenderPhp.php', |
|
80 | + 'LoggerAppenderRollingFile' => '/appenders/LoggerAppenderRollingFile.php', |
|
81 | + 'LoggerAppenderSocket' => '/appenders/LoggerAppenderSocket.php', |
|
82 | + 'LoggerAppenderSyslog' => '/appenders/LoggerAppenderSyslog.php', |
|
83 | + 'LoggerFormattingInfo' => '/helpers/LoggerFormattingInfo.php', |
|
84 | + 'LoggerOptionConverter' => '/helpers/LoggerOptionConverter.php', |
|
85 | + 'LoggerPatternConverter' => '/helpers/LoggerPatternConverter.php', |
|
86 | + 'LoggerBasicPatternConverter' => '/helpers/LoggerBasicPatternConverter.php', |
|
87 | + 'LoggerCategoryPatternConverter' => '/helpers/LoggerCategoryPatternConverter.php', |
|
88 | + 'LoggerClassNamePatternConverter' => '/helpers/LoggerClassNamePatternConverter.php', |
|
89 | + 'LoggerDatePatternConverter' => '/helpers/LoggerDatePatternConverter.php', |
|
90 | + 'LoggerLiteralPatternConverter' => '/helpers/LoggerLiteralPatternConverter.php', |
|
91 | + 'LoggerLocationPatternConverter' => '/helpers/LoggerLocationPatternConverter.php', |
|
92 | + 'LoggerMDCPatternConverter' => '/helpers/LoggerMDCPatternConverter.php', |
|
93 | + 'LoggerNamedPatternConverter' => '/helpers/LoggerNamedPatternConverter.php', |
|
94 | + 'LoggerBasicPatternConverter' => '/helpers/LoggerBasicPatternConverter.php', |
|
95 | + 'LoggerLiteralPatternConverter' => '/helpers/LoggerLiteralPatternConverter.php', |
|
96 | + 'LoggerDatePatternConverter' => '/helpers/LoggerDatePatternConverter.php', |
|
97 | + 'LoggerMDCPatternConverter' => '/helpers/LoggerMDCPatternConverter.php', |
|
98 | + 'LoggerLocationPatternConverter' => '/helpers/LoggerLocationPatternConverter.php', |
|
99 | + 'LoggerNamedPatternConverter' => '/helpers/LoggerNamedPatternConverter.php', |
|
100 | + 'LoggerClassNamePatternConverter' => '/helpers/LoggerClassNamePatternConverter.php', |
|
101 | + 'LoggerCategoryPatternConverter' => '/helpers/LoggerCategoryPatternConverter.php', |
|
102 | + 'LoggerPatternParser' => '/helpers/LoggerPatternParser.php', |
|
103 | + 'LoggerLayoutHtml' => '/layouts/LoggerLayoutHtml.php', |
|
104 | + 'LoggerLayoutSimple' => '/layouts/LoggerLayoutSimple.php', |
|
105 | + 'LoggerLayoutTTCC' => '/layouts/LoggerLayoutTTCC.php', |
|
106 | + 'LoggerLayoutPattern' => '/layouts/LoggerLayoutPattern.php', |
|
107 | + 'LoggerLayoutXml' => '/layouts/LoggerLayoutXml.php', |
|
108 | + 'LoggerRendererDefault' => '/renderers/LoggerRendererDefault.php', |
|
109 | + 'LoggerRendererObject' => '/renderers/LoggerRendererObject.php', |
|
110 | + 'LoggerRendererMap' => '/renderers/LoggerRendererMap.php', |
|
111 | + 'LoggerLocationInfo' => '/LoggerLocationInfo.php', |
|
112 | + 'LoggerLoggingEvent' => '/LoggerLoggingEvent.php', |
|
113 | + 'LoggerFilter' => '/LoggerFilter.php', |
|
114 | + 'LoggerFilterDenyAll' => '/filters/LoggerFilterDenyAll.php', |
|
115 | + 'LoggerFilterLevelMatch' => '/filters/LoggerFilterLevelMatch.php', |
|
116 | + 'LoggerFilterLevelRange' => '/filters/LoggerFilterLevelRange.php', |
|
117 | + 'LoggerFilterStringMatch' => '/filters/LoggerFilterStringMatch.php', |
|
118 | + ); |
|
119 | 119 | |
120 | - /** |
|
121 | - * Class autoloader |
|
122 | - * This method is provided to be invoked within an __autoload() magic method. |
|
123 | - * @param string class name |
|
124 | - */ |
|
125 | - public static function autoload($className) { |
|
126 | - if(isset(self::$_classes[$className])) { |
|
127 | - include LOG4PHP_DIR.self::$_classes[$className]; |
|
128 | - } |
|
129 | - } |
|
120 | + /** |
|
121 | + * Class autoloader |
|
122 | + * This method is provided to be invoked within an __autoload() magic method. |
|
123 | + * @param string class name |
|
124 | + */ |
|
125 | + public static function autoload($className) { |
|
126 | + if(isset(self::$_classes[$className])) { |
|
127 | + include LOG4PHP_DIR.self::$_classes[$className]; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Additivity is set to true by default, that is children inherit the |
|
133 | - * appenders of their ancestors by default. |
|
134 | - * @var boolean |
|
135 | - */ |
|
136 | - private $additive = true; |
|
137 | - |
|
138 | - /** @var string fully qualified class name */ |
|
139 | - private $fqcn = 'Logger'; |
|
131 | + /** |
|
132 | + * Additivity is set to true by default, that is children inherit the |
|
133 | + * appenders of their ancestors by default. |
|
134 | + * @var boolean |
|
135 | + */ |
|
136 | + private $additive = true; |
|
137 | + |
|
138 | + /** @var string fully qualified class name */ |
|
139 | + private $fqcn = 'Logger'; |
|
140 | 140 | |
141 | - /** @var LoggerLevel The assigned level of this category. */ |
|
142 | - private $level = null; |
|
141 | + /** @var LoggerLevel The assigned level of this category. */ |
|
142 | + private $level = null; |
|
143 | 143 | |
144 | - /** @var string name of this category. */ |
|
145 | - private $name = ''; |
|
144 | + /** @var string name of this category. */ |
|
145 | + private $name = ''; |
|
146 | 146 | |
147 | - /** @var Logger The parent of this category. Null if this is the root logger*/ |
|
148 | - private $parent = null; |
|
147 | + /** @var Logger The parent of this category. Null if this is the root logger*/ |
|
148 | + private $parent = null; |
|
149 | 149 | |
150 | - /** |
|
151 | - * @var array collection of appenders |
|
152 | - * @see LoggerAppender |
|
153 | - */ |
|
154 | - private $aai = array(); |
|
150 | + /** |
|
151 | + * @var array collection of appenders |
|
152 | + * @see LoggerAppender |
|
153 | + */ |
|
154 | + private $aai = array(); |
|
155 | 155 | |
156 | - /** the hierarchy used by log4php */ |
|
157 | - private static $hierarchy; |
|
158 | - |
|
159 | - /** the configurator class name */ |
|
160 | - private static $configurationClass = 'LoggerConfiguratorBasic'; |
|
161 | - |
|
162 | - /** the path to the configuration file */ |
|
163 | - private static $configurationFile = null; |
|
164 | - |
|
165 | - /** inidicates if log4php has already been initialized */ |
|
166 | - private static $initialized = false; |
|
167 | - |
|
168 | - /** |
|
169 | - * Constructor. |
|
170 | - * @param string $name Category name |
|
171 | - */ |
|
172 | - public function __construct($name) { |
|
173 | - $this->name = $name; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Return the category name. |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function getName() { |
|
181 | - return $this->name; |
|
182 | - } |
|
156 | + /** the hierarchy used by log4php */ |
|
157 | + private static $hierarchy; |
|
158 | + |
|
159 | + /** the configurator class name */ |
|
160 | + private static $configurationClass = 'LoggerConfiguratorBasic'; |
|
161 | + |
|
162 | + /** the path to the configuration file */ |
|
163 | + private static $configurationFile = null; |
|
164 | + |
|
165 | + /** inidicates if log4php has already been initialized */ |
|
166 | + private static $initialized = false; |
|
167 | + |
|
168 | + /** |
|
169 | + * Constructor. |
|
170 | + * @param string $name Category name |
|
171 | + */ |
|
172 | + public function __construct($name) { |
|
173 | + $this->name = $name; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Return the category name. |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function getName() { |
|
181 | + return $this->name; |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Returns the parent of this category. |
|
186 | - * @return Logger |
|
187 | - */ |
|
188 | - public function getParent() { |
|
189 | - return $this->parent; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Returns the hierarchy used by this Logger. |
|
194 | - * Caution: do not use this hierarchy unless you have called initialize(). |
|
195 | - * To get Loggers, use the Logger::getLogger and Logger::getRootLogger methods |
|
196 | - * instead of operating on on the hierarchy directly. |
|
197 | - * |
|
198 | - * @deprecated - will be moved to private |
|
199 | - * @return LoggerHierarchy |
|
200 | - */ |
|
201 | - public static function getHierarchy() { |
|
202 | - if(!isset(self::$hierarchy)) { |
|
203 | - self::$hierarchy = new LoggerHierarchy(new LoggerRoot()); |
|
204 | - } |
|
205 | - return self::$hierarchy; |
|
206 | - } |
|
207 | - |
|
208 | - /* Logging methods */ |
|
209 | - /** |
|
210 | - * Log a message object with the DEBUG level including the caller. |
|
211 | - * |
|
212 | - * @param mixed $message message |
|
213 | - * @param mixed $caller caller object or caller string id |
|
214 | - */ |
|
215 | - public function debug($message, $caller = null) { |
|
216 | - $this->logLevel($message, LoggerLevel::getLevelDebug(), $caller); |
|
217 | - } |
|
184 | + /** |
|
185 | + * Returns the parent of this category. |
|
186 | + * @return Logger |
|
187 | + */ |
|
188 | + public function getParent() { |
|
189 | + return $this->parent; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Returns the hierarchy used by this Logger. |
|
194 | + * Caution: do not use this hierarchy unless you have called initialize(). |
|
195 | + * To get Loggers, use the Logger::getLogger and Logger::getRootLogger methods |
|
196 | + * instead of operating on on the hierarchy directly. |
|
197 | + * |
|
198 | + * @deprecated - will be moved to private |
|
199 | + * @return LoggerHierarchy |
|
200 | + */ |
|
201 | + public static function getHierarchy() { |
|
202 | + if(!isset(self::$hierarchy)) { |
|
203 | + self::$hierarchy = new LoggerHierarchy(new LoggerRoot()); |
|
204 | + } |
|
205 | + return self::$hierarchy; |
|
206 | + } |
|
207 | + |
|
208 | + /* Logging methods */ |
|
209 | + /** |
|
210 | + * Log a message object with the DEBUG level including the caller. |
|
211 | + * |
|
212 | + * @param mixed $message message |
|
213 | + * @param mixed $caller caller object or caller string id |
|
214 | + */ |
|
215 | + public function debug($message, $caller = null) { |
|
216 | + $this->logLevel($message, LoggerLevel::getLevelDebug(), $caller); |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * Log a message object with the INFO Level. |
|
222 | - * |
|
223 | - * @param mixed $message message |
|
224 | - * @param mixed $caller caller object or caller string id |
|
225 | - */ |
|
226 | - public function info($message, $caller = null) { |
|
227 | - $this->logLevel($message, LoggerLevel::getLevelInfo(), $caller); |
|
228 | - } |
|
220 | + /** |
|
221 | + * Log a message object with the INFO Level. |
|
222 | + * |
|
223 | + * @param mixed $message message |
|
224 | + * @param mixed $caller caller object or caller string id |
|
225 | + */ |
|
226 | + public function info($message, $caller = null) { |
|
227 | + $this->logLevel($message, LoggerLevel::getLevelInfo(), $caller); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Log a message with the WARN level. |
|
232 | - * |
|
233 | - * @param mixed $message message |
|
234 | - * @param mixed $caller caller object or caller string id |
|
235 | - */ |
|
236 | - public function warn($message, $caller = null) { |
|
237 | - $this->logLevel($message, LoggerLevel::getLevelWarn(), $caller); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Log a message object with the ERROR level including the caller. |
|
242 | - * |
|
243 | - * @param mixed $message message |
|
244 | - * @param mixed $caller caller object or caller string id |
|
245 | - */ |
|
246 | - public function error($message, $caller = null) { |
|
247 | - $this->logLevel($message, LoggerLevel::getLevelError(), $caller); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Log a message object with the FATAL level including the caller. |
|
252 | - * |
|
253 | - * @param mixed $message message |
|
254 | - * @param mixed $caller caller object or caller string id |
|
255 | - */ |
|
256 | - public function fatal($message, $caller = null) { |
|
257 | - $this->logLevel($message, LoggerLevel::getLevelFatal(), $caller); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * This method creates a new logging event and logs the event without further checks. |
|
262 | - * |
|
263 | - * It should not be called directly. Use {@link info()}, {@link debug()}, {@link warn()}, |
|
264 | - * {@link error()} and {@link fatal()} wrappers. |
|
265 | - * |
|
266 | - * @param string $fqcn Fully Qualified Class Name of the Logger |
|
267 | - * @param mixed $caller caller object or caller string id |
|
268 | - * @param LoggerLevel $level log level |
|
269 | - * @param mixed $message message |
|
270 | - * @see LoggerLoggingEvent |
|
271 | - */ |
|
272 | - public function forcedLog($fqcn, $caller, $level, $message) { |
|
273 | - $this->callAppenders(new LoggerLoggingEvent($fqcn, $this, $level, $message)); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * Check whether this category is enabled for the DEBUG Level. |
|
279 | - * @return boolean |
|
280 | - */ |
|
281 | - public function isDebugEnabled() { |
|
282 | - return $this->isEnabledFor(LoggerLevel::getLevelDebug()); |
|
283 | - } |
|
230 | + /** |
|
231 | + * Log a message with the WARN level. |
|
232 | + * |
|
233 | + * @param mixed $message message |
|
234 | + * @param mixed $caller caller object or caller string id |
|
235 | + */ |
|
236 | + public function warn($message, $caller = null) { |
|
237 | + $this->logLevel($message, LoggerLevel::getLevelWarn(), $caller); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Log a message object with the ERROR level including the caller. |
|
242 | + * |
|
243 | + * @param mixed $message message |
|
244 | + * @param mixed $caller caller object or caller string id |
|
245 | + */ |
|
246 | + public function error($message, $caller = null) { |
|
247 | + $this->logLevel($message, LoggerLevel::getLevelError(), $caller); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Log a message object with the FATAL level including the caller. |
|
252 | + * |
|
253 | + * @param mixed $message message |
|
254 | + * @param mixed $caller caller object or caller string id |
|
255 | + */ |
|
256 | + public function fatal($message, $caller = null) { |
|
257 | + $this->logLevel($message, LoggerLevel::getLevelFatal(), $caller); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * This method creates a new logging event and logs the event without further checks. |
|
262 | + * |
|
263 | + * It should not be called directly. Use {@link info()}, {@link debug()}, {@link warn()}, |
|
264 | + * {@link error()} and {@link fatal()} wrappers. |
|
265 | + * |
|
266 | + * @param string $fqcn Fully Qualified Class Name of the Logger |
|
267 | + * @param mixed $caller caller object or caller string id |
|
268 | + * @param LoggerLevel $level log level |
|
269 | + * @param mixed $message message |
|
270 | + * @see LoggerLoggingEvent |
|
271 | + */ |
|
272 | + public function forcedLog($fqcn, $caller, $level, $message) { |
|
273 | + $this->callAppenders(new LoggerLoggingEvent($fqcn, $this, $level, $message)); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * Check whether this category is enabled for the DEBUG Level. |
|
279 | + * @return boolean |
|
280 | + */ |
|
281 | + public function isDebugEnabled() { |
|
282 | + return $this->isEnabledFor(LoggerLevel::getLevelDebug()); |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Check whether this category is enabled for a given Level passed as parameter. |
|
287 | - * |
|
288 | - * @param LoggerLevel level |
|
289 | - * @return boolean |
|
290 | - */ |
|
291 | - public function isEnabledFor($level) { |
|
292 | - return (bool)($level->isGreaterOrEqual($this->getEffectiveLevel())); |
|
293 | - } |
|
285 | + /** |
|
286 | + * Check whether this category is enabled for a given Level passed as parameter. |
|
287 | + * |
|
288 | + * @param LoggerLevel level |
|
289 | + * @return boolean |
|
290 | + */ |
|
291 | + public function isEnabledFor($level) { |
|
292 | + return (bool)($level->isGreaterOrEqual($this->getEffectiveLevel())); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * Check whether this category is enabled for the info Level. |
|
297 | - * @return boolean |
|
298 | - * @see LoggerLevel |
|
299 | - */ |
|
300 | - public function isInfoEnabled() { |
|
301 | - return $this->isEnabledFor(LoggerLevel::getLevelInfo()); |
|
302 | - } |
|
295 | + /** |
|
296 | + * Check whether this category is enabled for the info Level. |
|
297 | + * @return boolean |
|
298 | + * @see LoggerLevel |
|
299 | + */ |
|
300 | + public function isInfoEnabled() { |
|
301 | + return $this->isEnabledFor(LoggerLevel::getLevelInfo()); |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * This generic form is intended to be used by wrappers. |
|
306 | - * |
|
307 | - * @param LoggerLevel $priority a valid level |
|
308 | - * @param mixed $message message |
|
309 | - * @param mixed $caller caller object or caller string id |
|
310 | - */ |
|
311 | - public function log($priority, $message, $caller = null) { |
|
312 | - if($this->isEnabledFor($priority)) { |
|
313 | - $this->forcedLog($this->fqcn, $caller, $priority, $message); |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * If assertion parameter is false, then logs msg as an error statement. |
|
319 | - * |
|
320 | - * @param bool $assertion |
|
321 | - * @param string $msg message to log |
|
322 | - */ |
|
323 | - public function assertLog($assertion = true, $msg = '') { |
|
324 | - if($assertion == false) { |
|
325 | - $this->error($msg); |
|
326 | - } |
|
327 | - } |
|
304 | + /** |
|
305 | + * This generic form is intended to be used by wrappers. |
|
306 | + * |
|
307 | + * @param LoggerLevel $priority a valid level |
|
308 | + * @param mixed $message message |
|
309 | + * @param mixed $caller caller object or caller string id |
|
310 | + */ |
|
311 | + public function log($priority, $message, $caller = null) { |
|
312 | + if($this->isEnabledFor($priority)) { |
|
313 | + $this->forcedLog($this->fqcn, $caller, $priority, $message); |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * If assertion parameter is false, then logs msg as an error statement. |
|
319 | + * |
|
320 | + * @param bool $assertion |
|
321 | + * @param string $msg message to log |
|
322 | + */ |
|
323 | + public function assertLog($assertion = true, $msg = '') { |
|
324 | + if($assertion == false) { |
|
325 | + $this->error($msg); |
|
326 | + } |
|
327 | + } |
|
328 | 328 | |
329 | - private function logLevel($message, $level, $caller = null) { |
|
330 | - if($level->isGreaterOrEqual($this->getEffectiveLevel())) { |
|
331 | - $this->forcedLog($this->fqcn, $caller, $level, $message); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - /* Factory methods */ |
|
336 | - |
|
337 | - /** |
|
338 | - * Get a Logger by name (Delegate to {@link Logger}) |
|
339 | - * |
|
340 | - * @param string $name logger name |
|
341 | - * @param LoggerFactory $factory a {@link LoggerFactory} instance or null |
|
342 | - * @return Logger |
|
343 | - * @static |
|
344 | - */ |
|
345 | - public static function getLogger($name) { |
|
346 | - if(!self::isInitialized()) { |
|
347 | - self::initialize(); |
|
348 | - } |
|
349 | - return self::getHierarchy()->getLogger($name); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * get the Root Logger (Delegate to {@link Logger}) |
|
354 | - * @return LoggerRoot |
|
355 | - * @static |
|
356 | - */ |
|
357 | - public static function getRootLogger() { |
|
358 | - if(!self::isInitialized()) { |
|
359 | - self::initialize(); |
|
360 | - } |
|
361 | - return self::getHierarchy()->getRootLogger(); |
|
362 | - } |
|
363 | - |
|
364 | - /* Configuration methods */ |
|
365 | - |
|
366 | - /** |
|
367 | - * Add a new Appender to the list of appenders of this Category instance. |
|
368 | - * |
|
369 | - * @param LoggerAppender $newAppender |
|
370 | - */ |
|
371 | - public function addAppender($newAppender) { |
|
372 | - $appenderName = $newAppender->getName(); |
|
373 | - $this->aai[$appenderName] = $newAppender; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Remove all previously added appenders from this Category instance. |
|
378 | - */ |
|
379 | - public function removeAllAppenders() { |
|
380 | - $appenderNames = array_keys($this->aai); |
|
381 | - $enumAppenders = count($appenderNames); |
|
382 | - for($i = 0; $i < $enumAppenders; $i++) { |
|
383 | - $this->removeAppender($appenderNames[$i]); |
|
384 | - } |
|
385 | - } |
|
329 | + private function logLevel($message, $level, $caller = null) { |
|
330 | + if($level->isGreaterOrEqual($this->getEffectiveLevel())) { |
|
331 | + $this->forcedLog($this->fqcn, $caller, $level, $message); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + /* Factory methods */ |
|
336 | + |
|
337 | + /** |
|
338 | + * Get a Logger by name (Delegate to {@link Logger}) |
|
339 | + * |
|
340 | + * @param string $name logger name |
|
341 | + * @param LoggerFactory $factory a {@link LoggerFactory} instance or null |
|
342 | + * @return Logger |
|
343 | + * @static |
|
344 | + */ |
|
345 | + public static function getLogger($name) { |
|
346 | + if(!self::isInitialized()) { |
|
347 | + self::initialize(); |
|
348 | + } |
|
349 | + return self::getHierarchy()->getLogger($name); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * get the Root Logger (Delegate to {@link Logger}) |
|
354 | + * @return LoggerRoot |
|
355 | + * @static |
|
356 | + */ |
|
357 | + public static function getRootLogger() { |
|
358 | + if(!self::isInitialized()) { |
|
359 | + self::initialize(); |
|
360 | + } |
|
361 | + return self::getHierarchy()->getRootLogger(); |
|
362 | + } |
|
363 | + |
|
364 | + /* Configuration methods */ |
|
365 | + |
|
366 | + /** |
|
367 | + * Add a new Appender to the list of appenders of this Category instance. |
|
368 | + * |
|
369 | + * @param LoggerAppender $newAppender |
|
370 | + */ |
|
371 | + public function addAppender($newAppender) { |
|
372 | + $appenderName = $newAppender->getName(); |
|
373 | + $this->aai[$appenderName] = $newAppender; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Remove all previously added appenders from this Category instance. |
|
378 | + */ |
|
379 | + public function removeAllAppenders() { |
|
380 | + $appenderNames = array_keys($this->aai); |
|
381 | + $enumAppenders = count($appenderNames); |
|
382 | + for($i = 0; $i < $enumAppenders; $i++) { |
|
383 | + $this->removeAppender($appenderNames[$i]); |
|
384 | + } |
|
385 | + } |
|
386 | 386 | |
387 | - /** |
|
388 | - * Remove the appender passed as parameter form the list of appenders. |
|
389 | - * |
|
390 | - * @param mixed $appender can be an appender name or a {@link LoggerAppender} object |
|
391 | - */ |
|
392 | - public function removeAppender($appender) { |
|
393 | - if($appender instanceof LoggerAppender) { |
|
394 | - $appender->close(); |
|
395 | - unset($this->aai[$appender->getName()]); |
|
396 | - } else if (is_string($appender) and isset($this->aai[$appender])) { |
|
397 | - $this->aai[$appender]->close(); |
|
398 | - unset($this->aai[$appender]); |
|
399 | - } |
|
400 | - } |
|
387 | + /** |
|
388 | + * Remove the appender passed as parameter form the list of appenders. |
|
389 | + * |
|
390 | + * @param mixed $appender can be an appender name or a {@link LoggerAppender} object |
|
391 | + */ |
|
392 | + public function removeAppender($appender) { |
|
393 | + if($appender instanceof LoggerAppender) { |
|
394 | + $appender->close(); |
|
395 | + unset($this->aai[$appender->getName()]); |
|
396 | + } else if (is_string($appender) and isset($this->aai[$appender])) { |
|
397 | + $this->aai[$appender]->close(); |
|
398 | + unset($this->aai[$appender]); |
|
399 | + } |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Call the appenders in the hierarchy starting at this. |
|
404 | - * |
|
405 | - * @param LoggerLoggingEvent $event |
|
406 | - */ |
|
407 | - public function callAppenders($event) { |
|
408 | - if(count($this->aai) > 0) { |
|
409 | - foreach(array_keys($this->aai) as $appenderName) { |
|
410 | - $this->aai[$appenderName]->doAppend($event); |
|
411 | - } |
|
412 | - } |
|
413 | - if($this->parent != null and $this->getAdditivity()) { |
|
414 | - $this->parent->callAppenders($event); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Get the appenders contained in this category as an array. |
|
420 | - * @return array collection of appenders |
|
421 | - */ |
|
422 | - public function getAllAppenders() { |
|
423 | - return array_values($this->aai); |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Look for the appender named as name. |
|
428 | - * @return LoggerAppender |
|
429 | - */ |
|
430 | - public function getAppender($name) { |
|
431 | - return $this->aai[$name]; |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Get the additivity flag for this Category instance. |
|
436 | - * @return boolean |
|
437 | - */ |
|
438 | - public function getAdditivity() { |
|
439 | - return $this->additive; |
|
440 | - } |
|
402 | + /** |
|
403 | + * Call the appenders in the hierarchy starting at this. |
|
404 | + * |
|
405 | + * @param LoggerLoggingEvent $event |
|
406 | + */ |
|
407 | + public function callAppenders($event) { |
|
408 | + if(count($this->aai) > 0) { |
|
409 | + foreach(array_keys($this->aai) as $appenderName) { |
|
410 | + $this->aai[$appenderName]->doAppend($event); |
|
411 | + } |
|
412 | + } |
|
413 | + if($this->parent != null and $this->getAdditivity()) { |
|
414 | + $this->parent->callAppenders($event); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Get the appenders contained in this category as an array. |
|
420 | + * @return array collection of appenders |
|
421 | + */ |
|
422 | + public function getAllAppenders() { |
|
423 | + return array_values($this->aai); |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Look for the appender named as name. |
|
428 | + * @return LoggerAppender |
|
429 | + */ |
|
430 | + public function getAppender($name) { |
|
431 | + return $this->aai[$name]; |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Get the additivity flag for this Category instance. |
|
436 | + * @return boolean |
|
437 | + */ |
|
438 | + public function getAdditivity() { |
|
439 | + return $this->additive; |
|
440 | + } |
|
441 | 441 | |
442 | - /** |
|
443 | - * Starting from this category, search the category hierarchy for a non-null level and return it. |
|
444 | - * @see LoggerLevel |
|
445 | - * @return LoggerLevel or null |
|
446 | - */ |
|
447 | - public function getEffectiveLevel() { |
|
448 | - for($c = $this; $c != null; $c = $c->parent) { |
|
449 | - if($c->getLevel() !== null) { |
|
450 | - return $c->getLevel(); |
|
451 | - } |
|
452 | - } |
|
453 | - return null; |
|
454 | - } |
|
442 | + /** |
|
443 | + * Starting from this category, search the category hierarchy for a non-null level and return it. |
|
444 | + * @see LoggerLevel |
|
445 | + * @return LoggerLevel or null |
|
446 | + */ |
|
447 | + public function getEffectiveLevel() { |
|
448 | + for($c = $this; $c != null; $c = $c->parent) { |
|
449 | + if($c->getLevel() !== null) { |
|
450 | + return $c->getLevel(); |
|
451 | + } |
|
452 | + } |
|
453 | + return null; |
|
454 | + } |
|
455 | 455 | |
456 | - /** |
|
457 | - * Returns the assigned Level, if any, for this Category. |
|
458 | - * @return LoggerLevel or null |
|
459 | - */ |
|
460 | - public function getLevel() { |
|
461 | - return $this->level; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Set the level of this Category. |
|
466 | - * |
|
467 | - * @param LoggerLevel $level a level string or a level constant |
|
468 | - */ |
|
469 | - public function setLevel($level) { |
|
470 | - $this->level = $level; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Clears all logger definitions |
|
475 | - * |
|
476 | - * @static |
|
477 | - * @return boolean |
|
478 | - */ |
|
479 | - public static function clear() { |
|
480 | - return self::getHierarchy()->clear(); |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Destroy configurations for logger definitions |
|
485 | - * |
|
486 | - * @static |
|
487 | - * @return boolean |
|
488 | - */ |
|
489 | - public static function resetConfiguration() { |
|
490 | - $result = self::getHierarchy()->resetConfiguration(); |
|
491 | - self::$initialized = false; |
|
492 | - self::$configurationClass = 'LoggerConfiguratorBasic'; |
|
493 | - self::$configurationFile = null; |
|
494 | - return $result; |
|
495 | - } |
|
456 | + /** |
|
457 | + * Returns the assigned Level, if any, for this Category. |
|
458 | + * @return LoggerLevel or null |
|
459 | + */ |
|
460 | + public function getLevel() { |
|
461 | + return $this->level; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Set the level of this Category. |
|
466 | + * |
|
467 | + * @param LoggerLevel $level a level string or a level constant |
|
468 | + */ |
|
469 | + public function setLevel($level) { |
|
470 | + $this->level = $level; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Clears all logger definitions |
|
475 | + * |
|
476 | + * @static |
|
477 | + * @return boolean |
|
478 | + */ |
|
479 | + public static function clear() { |
|
480 | + return self::getHierarchy()->clear(); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Destroy configurations for logger definitions |
|
485 | + * |
|
486 | + * @static |
|
487 | + * @return boolean |
|
488 | + */ |
|
489 | + public static function resetConfiguration() { |
|
490 | + $result = self::getHierarchy()->resetConfiguration(); |
|
491 | + self::$initialized = false; |
|
492 | + self::$configurationClass = 'LoggerConfiguratorBasic'; |
|
493 | + self::$configurationFile = null; |
|
494 | + return $result; |
|
495 | + } |
|
496 | 496 | |
497 | - /** |
|
498 | - * Safely close all appenders. |
|
499 | - * This is not longer necessary due the appenders shutdown via |
|
500 | - * destructors. |
|
501 | - * @deprecated |
|
502 | - * @static |
|
503 | - */ |
|
504 | - public static function shutdown() { |
|
505 | - return self::getHierarchy()->shutdown(); |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * check if a given logger exists. |
|
510 | - * |
|
511 | - * @param string $name logger name |
|
512 | - * @static |
|
513 | - * @return boolean |
|
514 | - */ |
|
515 | - public static function exists($name) { |
|
516 | - return self::getHierarchy()->exists($name); |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Returns an array this whole Logger instances. |
|
521 | - * |
|
522 | - * @static |
|
523 | - * @see Logger |
|
524 | - * @return array |
|
525 | - */ |
|
526 | - public static function getCurrentLoggers() { |
|
527 | - return self::getHierarchy()->getCurrentLoggers(); |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Is the appender passed as parameter attached to this category? |
|
532 | - * |
|
533 | - * @param LoggerAppender $appender |
|
534 | - */ |
|
535 | - public function isAttached($appender) { |
|
536 | - return isset($this->aai[$appender->getName()]); |
|
537 | - } |
|
497 | + /** |
|
498 | + * Safely close all appenders. |
|
499 | + * This is not longer necessary due the appenders shutdown via |
|
500 | + * destructors. |
|
501 | + * @deprecated |
|
502 | + * @static |
|
503 | + */ |
|
504 | + public static function shutdown() { |
|
505 | + return self::getHierarchy()->shutdown(); |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * check if a given logger exists. |
|
510 | + * |
|
511 | + * @param string $name logger name |
|
512 | + * @static |
|
513 | + * @return boolean |
|
514 | + */ |
|
515 | + public static function exists($name) { |
|
516 | + return self::getHierarchy()->exists($name); |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Returns an array this whole Logger instances. |
|
521 | + * |
|
522 | + * @static |
|
523 | + * @see Logger |
|
524 | + * @return array |
|
525 | + */ |
|
526 | + public static function getCurrentLoggers() { |
|
527 | + return self::getHierarchy()->getCurrentLoggers(); |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Is the appender passed as parameter attached to this category? |
|
532 | + * |
|
533 | + * @param LoggerAppender $appender |
|
534 | + */ |
|
535 | + public function isAttached($appender) { |
|
536 | + return isset($this->aai[$appender->getName()]); |
|
537 | + } |
|
538 | 538 | |
539 | - /** |
|
540 | - * Set the additivity flag for this Category instance. |
|
541 | - * |
|
542 | - * @param boolean $additive |
|
543 | - */ |
|
544 | - public function setAdditivity($additive) { |
|
545 | - $this->additive = (bool)$additive; |
|
546 | - } |
|
539 | + /** |
|
540 | + * Set the additivity flag for this Category instance. |
|
541 | + * |
|
542 | + * @param boolean $additive |
|
543 | + */ |
|
544 | + public function setAdditivity($additive) { |
|
545 | + $this->additive = (bool)$additive; |
|
546 | + } |
|
547 | 547 | |
548 | - /** |
|
549 | - * Sets the parent logger of this logger |
|
550 | - */ |
|
551 | - public function setParent(Logger $logger) { |
|
552 | - $this->parent = $logger; |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * Configures Log4PHP. |
|
557 | - * This method needs to be called before the first logging event |
|
558 | - * has occured. If this methode is never called, the standard configuration |
|
559 | - * takes place (@see LoggerConfiguratorBasic). |
|
560 | - * If only the configuration file is given, the configurator class will |
|
561 | - * be the XML Configurator or the INI Configurator, if no .xml ending |
|
562 | - * could be determined. |
|
563 | - * |
|
564 | - * If a custom configurator should be used, the configuration file |
|
565 | - * is either null or the path to file the custom configurator uses. |
|
566 | - * Make sure the configurator is already or can be loaded by PHP when necessary. |
|
567 | - * |
|
568 | - * @param String $configurationFile the configuration file |
|
569 | - * @param String $configurationClass the configurator class |
|
570 | - */ |
|
571 | - public static function configure($configurationFile = null, |
|
572 | - $configurationClass = null ) { |
|
573 | - if($configurationClass === null && $configurationFile === null) { |
|
574 | - self::$configurationClass = 'LoggerConfiguratorBasic'; |
|
575 | - return; |
|
576 | - } |
|
548 | + /** |
|
549 | + * Sets the parent logger of this logger |
|
550 | + */ |
|
551 | + public function setParent(Logger $logger) { |
|
552 | + $this->parent = $logger; |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * Configures Log4PHP. |
|
557 | + * This method needs to be called before the first logging event |
|
558 | + * has occured. If this methode is never called, the standard configuration |
|
559 | + * takes place (@see LoggerConfiguratorBasic). |
|
560 | + * If only the configuration file is given, the configurator class will |
|
561 | + * be the XML Configurator or the INI Configurator, if no .xml ending |
|
562 | + * could be determined. |
|
563 | + * |
|
564 | + * If a custom configurator should be used, the configuration file |
|
565 | + * is either null or the path to file the custom configurator uses. |
|
566 | + * Make sure the configurator is already or can be loaded by PHP when necessary. |
|
567 | + * |
|
568 | + * @param String $configurationFile the configuration file |
|
569 | + * @param String $configurationClass the configurator class |
|
570 | + */ |
|
571 | + public static function configure($configurationFile = null, |
|
572 | + $configurationClass = null ) { |
|
573 | + if($configurationClass === null && $configurationFile === null) { |
|
574 | + self::$configurationClass = 'LoggerConfiguratorBasic'; |
|
575 | + return; |
|
576 | + } |
|
577 | 577 | |
578 | - if($configurationClass !== null) { |
|
579 | - self::$configurationFile = $configurationFile; |
|
580 | - self::$configurationClass = $configurationClass; |
|
581 | - return; |
|
582 | - } |
|
578 | + if($configurationClass !== null) { |
|
579 | + self::$configurationFile = $configurationFile; |
|
580 | + self::$configurationClass = $configurationClass; |
|
581 | + return; |
|
582 | + } |
|
583 | 583 | |
584 | - if (strtolower(substr( $configurationFile, -4 )) == '.xml') { |
|
585 | - self::$configurationFile = $configurationFile; |
|
586 | - self::$configurationClass = 'LoggerConfiguratorXml'; |
|
587 | - } else { |
|
588 | - self::$configurationFile = $configurationFile; |
|
589 | - self::$configurationClass = 'LoggerConfiguratorIni'; |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Returns the current configurator |
|
595 | - * @return the configurator |
|
596 | - */ |
|
597 | - public static function getConfigurationClass() { |
|
598 | - return self::$configurationClass; |
|
599 | - } |
|
600 | - |
|
601 | - /** |
|
602 | - * Returns the current configuration file |
|
603 | - * @return the configuration file |
|
604 | - */ |
|
605 | - public static function getConfigurationFile() { |
|
606 | - return self::$configurationFile; |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Returns, true, if the log4php framework is already initialized |
|
611 | - */ |
|
612 | - private static function isInitialized() { |
|
613 | - return self::$initialized; |
|
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * Initializes the log4php framework. |
|
618 | - * @return boolean |
|
619 | - */ |
|
620 | - public static function initialize() { |
|
621 | - self::$initialized = true; |
|
622 | - $instance = LoggerReflectionUtils::createObject(self::$configurationClass); |
|
623 | - $result = $instance->configure(self::getHierarchy(), self::$configurationFile); |
|
624 | - return $result; |
|
625 | - } |
|
584 | + if (strtolower(substr( $configurationFile, -4 )) == '.xml') { |
|
585 | + self::$configurationFile = $configurationFile; |
|
586 | + self::$configurationClass = 'LoggerConfiguratorXml'; |
|
587 | + } else { |
|
588 | + self::$configurationFile = $configurationFile; |
|
589 | + self::$configurationClass = 'LoggerConfiguratorIni'; |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Returns the current configurator |
|
595 | + * @return the configurator |
|
596 | + */ |
|
597 | + public static function getConfigurationClass() { |
|
598 | + return self::$configurationClass; |
|
599 | + } |
|
600 | + |
|
601 | + /** |
|
602 | + * Returns the current configuration file |
|
603 | + * @return the configuration file |
|
604 | + */ |
|
605 | + public static function getConfigurationFile() { |
|
606 | + return self::$configurationFile; |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Returns, true, if the log4php framework is already initialized |
|
611 | + */ |
|
612 | + private static function isInitialized() { |
|
613 | + return self::$initialized; |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * Initializes the log4php framework. |
|
618 | + * @return boolean |
|
619 | + */ |
|
620 | + public static function initialize() { |
|
621 | + self::$initialized = true; |
|
622 | + $instance = LoggerReflectionUtils::createObject(self::$configurationClass); |
|
623 | + $result = $instance->configure(self::getHierarchy(), self::$configurationFile); |
|
624 | + return $result; |
|
625 | + } |
|
626 | 626 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param string class name |
124 | 124 | */ |
125 | 125 | public static function autoload($className) { |
126 | - if(isset(self::$_classes[$className])) { |
|
126 | + if (isset(self::$_classes[$className])) { |
|
127 | 127 | include LOG4PHP_DIR.self::$_classes[$className]; |
128 | 128 | } |
129 | 129 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @return LoggerHierarchy |
200 | 200 | */ |
201 | 201 | public static function getHierarchy() { |
202 | - if(!isset(self::$hierarchy)) { |
|
202 | + if (!isset(self::$hierarchy)) { |
|
203 | 203 | self::$hierarchy = new LoggerHierarchy(new LoggerRoot()); |
204 | 204 | } |
205 | 205 | return self::$hierarchy; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | 291 | public function isEnabledFor($level) { |
292 | - return (bool)($level->isGreaterOrEqual($this->getEffectiveLevel())); |
|
292 | + return (bool) ($level->isGreaterOrEqual($this->getEffectiveLevel())); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @param mixed $caller caller object or caller string id |
310 | 310 | */ |
311 | 311 | public function log($priority, $message, $caller = null) { |
312 | - if($this->isEnabledFor($priority)) { |
|
312 | + if ($this->isEnabledFor($priority)) { |
|
313 | 313 | $this->forcedLog($this->fqcn, $caller, $priority, $message); |
314 | 314 | } |
315 | 315 | } |
@@ -321,13 +321,13 @@ discard block |
||
321 | 321 | * @param string $msg message to log |
322 | 322 | */ |
323 | 323 | public function assertLog($assertion = true, $msg = '') { |
324 | - if($assertion == false) { |
|
324 | + if ($assertion == false) { |
|
325 | 325 | $this->error($msg); |
326 | 326 | } |
327 | 327 | } |
328 | 328 | |
329 | 329 | private function logLevel($message, $level, $caller = null) { |
330 | - if($level->isGreaterOrEqual($this->getEffectiveLevel())) { |
|
330 | + if ($level->isGreaterOrEqual($this->getEffectiveLevel())) { |
|
331 | 331 | $this->forcedLog($this->fqcn, $caller, $level, $message); |
332 | 332 | } |
333 | 333 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | * @static |
344 | 344 | */ |
345 | 345 | public static function getLogger($name) { |
346 | - if(!self::isInitialized()) { |
|
346 | + if (!self::isInitialized()) { |
|
347 | 347 | self::initialize(); |
348 | 348 | } |
349 | 349 | return self::getHierarchy()->getLogger($name); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @static |
356 | 356 | */ |
357 | 357 | public static function getRootLogger() { |
358 | - if(!self::isInitialized()) { |
|
358 | + if (!self::isInitialized()) { |
|
359 | 359 | self::initialize(); |
360 | 360 | } |
361 | 361 | return self::getHierarchy()->getRootLogger(); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | public function removeAllAppenders() { |
380 | 380 | $appenderNames = array_keys($this->aai); |
381 | 381 | $enumAppenders = count($appenderNames); |
382 | - for($i = 0; $i < $enumAppenders; $i++) { |
|
382 | + for ($i = 0; $i < $enumAppenders; $i++) { |
|
383 | 383 | $this->removeAppender($appenderNames[$i]); |
384 | 384 | } |
385 | 385 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * @param mixed $appender can be an appender name or a {@link LoggerAppender} object |
391 | 391 | */ |
392 | 392 | public function removeAppender($appender) { |
393 | - if($appender instanceof LoggerAppender) { |
|
393 | + if ($appender instanceof LoggerAppender) { |
|
394 | 394 | $appender->close(); |
395 | 395 | unset($this->aai[$appender->getName()]); |
396 | 396 | } else if (is_string($appender) and isset($this->aai[$appender])) { |
@@ -405,12 +405,12 @@ discard block |
||
405 | 405 | * @param LoggerLoggingEvent $event |
406 | 406 | */ |
407 | 407 | public function callAppenders($event) { |
408 | - if(count($this->aai) > 0) { |
|
409 | - foreach(array_keys($this->aai) as $appenderName) { |
|
408 | + if (count($this->aai) > 0) { |
|
409 | + foreach (array_keys($this->aai) as $appenderName) { |
|
410 | 410 | $this->aai[$appenderName]->doAppend($event); |
411 | 411 | } |
412 | 412 | } |
413 | - if($this->parent != null and $this->getAdditivity()) { |
|
413 | + if ($this->parent != null and $this->getAdditivity()) { |
|
414 | 414 | $this->parent->callAppenders($event); |
415 | 415 | } |
416 | 416 | } |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * @return LoggerLevel or null |
446 | 446 | */ |
447 | 447 | public function getEffectiveLevel() { |
448 | - for($c = $this; $c != null; $c = $c->parent) { |
|
449 | - if($c->getLevel() !== null) { |
|
448 | + for ($c = $this; $c != null; $c = $c->parent) { |
|
449 | + if ($c->getLevel() !== null) { |
|
450 | 450 | return $c->getLevel(); |
451 | 451 | } |
452 | 452 | } |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * @param boolean $additive |
543 | 543 | */ |
544 | 544 | public function setAdditivity($additive) { |
545 | - $this->additive = (bool)$additive; |
|
545 | + $this->additive = (bool) $additive; |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -569,19 +569,19 @@ discard block |
||
569 | 569 | * @param String $configurationClass the configurator class |
570 | 570 | */ |
571 | 571 | public static function configure($configurationFile = null, |
572 | - $configurationClass = null ) { |
|
573 | - if($configurationClass === null && $configurationFile === null) { |
|
572 | + $configurationClass = null) { |
|
573 | + if ($configurationClass === null && $configurationFile === null) { |
|
574 | 574 | self::$configurationClass = 'LoggerConfiguratorBasic'; |
575 | 575 | return; |
576 | 576 | } |
577 | 577 | |
578 | - if($configurationClass !== null) { |
|
578 | + if ($configurationClass !== null) { |
|
579 | 579 | self::$configurationFile = $configurationFile; |
580 | 580 | self::$configurationClass = $configurationClass; |
581 | 581 | return; |
582 | 582 | } |
583 | 583 | |
584 | - if (strtolower(substr( $configurationFile, -4 )) == '.xml') { |
|
584 | + if (strtolower(substr($configurationFile, -4)) == '.xml') { |
|
585 | 585 | self::$configurationFile = $configurationFile; |
586 | 586 | self::$configurationClass = 'LoggerConfiguratorXml'; |
587 | 587 | } else { |
@@ -26,7 +26,9 @@ |
||
26 | 26 | * |
27 | 27 | * @var string |
28 | 28 | */ |
29 | -if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); |
|
29 | +if (!defined('LOG4PHP_DIR')) { |
|
30 | + define('LOG4PHP_DIR', dirname(__FILE__)); |
|
31 | +} |
|
30 | 32 | |
31 | 33 | spl_autoload_register(array('Logger', 'autoload')); |
32 | 34 |