[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * log4php is a PHP port of the log4j java logging package. 4 * 5 * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p> 6 * <p>Design, strategies and part of the methods documentation are developed by log4j team 7 * (Ceki G�lc� as log4j project founder and 8 * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p> 9 * 10 * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br> 11 * For more information, please see {@link http://www.vxr.it/log4php/}.</p> 12 * 13 * <p>This software is published under the terms of the LGPL License 14 * a copy of which has been included with this distribution in the LICENSE file.</p> 15 * 16 * @package log4php 17 */ 18 19 /** 20 * @ignore 21 */ 22 if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); 23 24 require_once (LOG4PHP_DIR . '/config/LoggerPropertySetter.php'); 25 require_once (LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); 26 require_once (LOG4PHP_DIR . '/or/LoggerObjectRenderer.php'); 27 require_once (LOG4PHP_DIR . '/or/LoggerRendererMap.php'); 28 require_once (LOG4PHP_DIR . '/spi/LoggerConfigurator.php'); 29 require_once (LOG4PHP_DIR . '/spi/LoggerFilter.php'); 30 require_once (LOG4PHP_DIR . '/LoggerAppender.php'); 31 require_once (LOG4PHP_DIR . '/LoggerDefaultCategoryFactory.php'); 32 require_once (LOG4PHP_DIR . '/LoggerLayout.php'); 33 require_once (LOG4PHP_DIR . '/LoggerLevel.php'); 34 require_once (LOG4PHP_DIR . '/LoggerManager.php'); 35 36 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX', "log4php.category."); 37 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX', "log4php.logger."); 38 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_FACTORY_PREFIX', "log4php.factory"); 39 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX', "log4php.additivity."); 40 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX', "log4php.rootCategory"); 41 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX', "log4php.rootLogger"); 42 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX', "log4php.appender."); 43 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX', "log4php.renderer."); 44 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX', "log4php.threshold"); 45 46 /** 47 * Key for specifying the {@link LoggerFactory}. 48 */ 49 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY', "log4php.loggerFactory"); 50 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY', "log4php.debug"); 51 define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME', "root"); 52 53 54 55 /** 56 * Allows the configuration of log4php from an external file. 57 * 58 * See {@link doConfigure()} for the expected format. 59 * 60 * <p>It is sometimes useful to see how log4php is reading configuration 61 * files. You can enable log4php internal logging by defining the 62 * <b>log4php.debug</b> variable.</p> 63 * 64 * <p>The <i>LoggerPropertyConfigurator</i> does not handle the 65 * advanced configuration features supported by the {@link LoggerDOMConfigurator} 66 * such as support for {@link LoggerFilter}, 67 custom {@link LoggerErrorHandlers}, nested appenders such as the 68 {@link Logger AsyncAppender}, 69 * etc. 70 * 71 * <p>All option <i>values</i> admit variable substitution. The 72 * syntax of variable substitution is similar to that of Unix 73 * shells. The string between an opening <b>"${"</b> and 74 * closing <b>"}"</b> is interpreted as a key. The value of 75 * the substituted variable can be defined as a system property or in 76 * the configuration file itself. The value of the key is first 77 * searched in the defined constants, in the enviroments variables 78 * and if not found there, it is 79 * then searched in the configuration file being parsed. The 80 * corresponding value replaces the ${variableName} sequence.</p> 81 * <p>For example, if <b>$_ENV['home']</b> env var is set to 82 * <b>/home/xyz</b>, then every occurrence of the sequence 83 * <b>${home}</b> will be interpreted as 84 * <b>/home/xyz</b>. See {@link LoggerOptionConverter::getSystemProperty()} 85 * for details.</p> 86 * 87 * @author VxR <[email protected]> 88 * @version $Revision: 1.6 $ 89 * @package log4php 90 * @since 0.5 91 */ 92 class LoggerPropertyConfigurator extends LoggerConfigurator { 93 94 /** 95 * @var LoggerFactory 96 */ 97 var $loggerFactory = null; 98 99 /** 100 * Constructor 101 */ 102 function LoggerPropertyConfigurator() 103 { 104 $this->loggerFactory = new LoggerDefaultCategoryFactory(); 105 } 106 107 /** 108 * Configure the default repository using the resource pointed by <b>url</b>. 109 * <b>Url</b> is any valid resurce as defined in {@link PHP_MANUAL#file} function. 110 * Note that the resource will be search with <i>use_include_path</i> parameter 111 * set to "1". 112 * 113 * @param string $url 114 * @return boolean configuration result 115 * @static 116 */ 117 function configure($url = '') 118 { 119 $configurator = new LoggerPropertyConfigurator(); 120 $repository =& LoggerManager::getLoggerRepository(); 121 return $configurator->doConfigure($url, $repository); 122 } 123 124 /** 125 * Read configuration from a file. 126 * 127 * <p>The function {@link PHP_MANUAL#parse_ini_file} is used to read the 128 * file.</p> 129 * 130 * <b>The existing configuration is not cleared nor reset.</b> 131 * If you require a different behavior, then call 132 * {@link LoggerManager::resetConfiguration()} 133 * method before calling {@link doConfigure()}. 134 * 135 * <p>The configuration file consists of statements in the format 136 * <b>key=value</b>. The syntax of different configuration 137 * elements are discussed below. 138 * 139 * <p><b>Repository-wide threshold</b></p> 140 * 141 * <p>The repository-wide threshold filters logging requests by level 142 * regardless of logger. The syntax is: 143 * 144 * <pre> 145 * log4php.threshold=[level] 146 * </pre> 147 * 148 * <p>The level value can consist of the string values OFF, FATAL, 149 * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A 150 * custom level value can be specified in the form 151 * <samp>level#classname</samp>. By default the repository-wide threshold is set 152 * to the lowest possible value, namely the level <b>ALL</b>. 153 * </p> 154 * 155 * 156 * <p><b>Appender configuration</b></p> 157 * 158 * <p>Appender configuration syntax is:</p> 159 * <pre> 160 * ; For appender named <i>appenderName</i>, set its class. 161 * ; Note: The appender name can contain dots. 162 * log4php.appender.appenderName=name_of_appender_class 163 * 164 * ; Set appender specific options. 165 * 166 * log4php.appender.appenderName.option1=value1 167 * log4php.appender.appenderName.optionN=valueN 168 * </pre> 169 * 170 * For each named appender you can configure its {@link LoggerLayout}. The 171 * syntax for configuring an appender's layout is: 172 * <pre> 173 * log4php.appender.appenderName.layout=name_of_layout_class 174 * log4php.appender.appenderName.layout.option1=value1 175 * .... 176 * log4php.appender.appenderName.layout.optionN=valueN 177 * </pre> 178 * 179 * <p><b>Configuring loggers</b></p> 180 * 181 * <p>The syntax for configuring the root logger is: 182 * <pre> 183 * log4php.rootLogger=[level], appenderName, appenderName, ... 184 * </pre> 185 * 186 * <p>This syntax means that an optional <i>level</i> can be 187 * supplied followed by appender names separated by commas. 188 * 189 * <p>The level value can consist of the string values OFF, FATAL, 190 * ERROR, WARN, INFO, DEBUG, ALL or a <i>custom level</i> value. A 191 * custom level value can be specified in the form</p> 192 * 193 * <pre>level#classname</pre> 194 * 195 * <p>If a level value is specified, then the root level is set 196 * to the corresponding level. If no level value is specified, 197 * then the root level remains untouched. 198 * 199 * <p>The root logger can be assigned multiple appenders. 200 * 201 * <p>Each <i>appenderName</i> (separated by commas) will be added to 202 * the root logger. The named appender is defined using the 203 * appender syntax defined above. 204 * 205 * <p>For non-root categories the syntax is almost the same: 206 * <pre> 207 * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... 208 * </pre> 209 * 210 * <p>The meaning of the optional level value is discussed above 211 * in relation to the root logger. In addition however, the value 212 * INHERITED can be specified meaning that the named logger should 213 * inherit its level from the logger hierarchy.</p> 214 * 215 * <p>If no level value is supplied, then the level of the 216 * named logger remains untouched.</p> 217 * 218 * <p>By default categories inherit their level from the 219 * hierarchy. However, if you set the level of a logger and later 220 * decide that that logger should inherit its level, then you should 221 * specify INHERITED as the value for the level value. NULL is a 222 * synonym for INHERITED.</p> 223 * 224 * <p>Similar to the root logger syntax, each <i>appenderName</i> 225 * (separated by commas) will be attached to the named logger.</p> 226 * 227 * <p>See the <i>appender additivity rule</i> in the user manual for 228 * the meaning of the <b>additivity</b> flag. 229 * 230 * <p><b>ObjectRenderers</b></p> 231 * 232 * <p>You can customize the way message objects of a given type are 233 * converted to String before being logged. This is done by 234 * specifying a {@link LoggerObjectRenderer} 235 * for the object type would like to customize.</p> 236 * 237 * <p>The syntax is: 238 * 239 * <pre> 240 * log4php.renderer.name_of_rendered_class=name_of_rendering.class 241 * </pre> 242 * 243 * As in, 244 * <pre> 245 * log4php.renderer.myFruit=myFruitRenderer 246 * </pre> 247 * 248 * <p><b>Logger Factories</b></p> 249 * 250 * The usage of custom logger factories is discouraged and no longer 251 * documented. 252 * 253 * <p><b>Example</b></p> 254 * 255 * <p>An example configuration is given below. Other configuration 256 * file examples are given in the <b>tests</b> folder. 257 * 258 * <pre> 259 * ; Set options for appender named "A1". 260 * ; Appender "A1" will be a SyslogAppender 261 * log4php.appender.A1=SyslogAppender 262 * 263 * ; The syslog daemon resides on www.abc.net 264 * log4php.appender.A1.SyslogHost=www.abc.net 265 * 266 * ; A1's layout is a LoggerPatternLayout, using the conversion pattern 267 * ; <b>%r %-5p %c{2} %M.%L %x - %m%n</b>. Thus, the log output will 268 * ; include the relative time since the start of the application in 269 * ; milliseconds, followed by the level of the log request, 270 * ; followed by the two rightmost components of the logger name, 271 * ; followed by the callers method name, followed by the line number, 272 * ; the nested disgnostic context and finally the message itself. 273 * ; Refer to the documentation of LoggerPatternLayout} for further information 274 * ; on the syntax of the ConversionPattern key. 275 * log4php.appender.A1.layout=LoggerPatternLayout 276 * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n" 277 * 278 * ; Set options for appender named "A2" 279 * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB 280 * ; using at most one backup file. A2's layout is TTCC, using the 281 * ; ISO8061 date format with context printing enabled. 282 * log4php.appender.A2=LoggerAppenderRollingFile 283 * log4php.appender.A2.MaxFileSize=10MB 284 * log4php.appender.A2.MaxBackupIndex=1 285 * log4php.appender.A2.layout=LoggerLayoutTTCC 286 * log4php.appender.A2.layout.ContextPrinting="true" 287 * log4php.appender.A2.layout.DateFormat="%c" 288 * 289 * ; Root logger set to DEBUG using the A2 appender defined above. 290 * log4php.rootLogger=DEBUG, A2 291 * 292 * ; Logger definitions: 293 * ; The SECURITY logger inherits is level from root. However, it's output 294 * ; will go to A1 appender defined above. It's additivity is non-cumulative. 295 * log4php.logger.SECURITY=INHERIT, A1 296 * log4php.additivity.SECURITY=false 297 * 298 * ; Only warnings or above will be logged for the logger "SECURITY.access". 299 * ; Output will go to A1. 300 * log4php.logger.SECURITY.access=WARN 301 * 302 * 303 * ; The logger "class.of.the.day" inherits its level from the 304 * ; logger hierarchy. Output will go to the appender's of the root 305 * ; logger, A2 in this case. 306 * log4php.logger.class.of.the.day=INHERIT 307 * </pre> 308 * 309 * <p>Refer to the <b>setOption</b> method in each Appender and 310 * Layout for class specific options.</p> 311 * 312 * <p>Use the <b>";"</b> character at the 313 * beginning of a line for comments.</p> 314 * 315 * @param string $url The name of the configuration file where the 316 * configuration information is stored. 317 * @param LoggerHierarchy &$repository the repository to apply the configuration 318 */ 319 function doConfigure($url, &$repository) 320 { 321 $properties = @parse_ini_file($url); 322 if ($properties === false) { 323 LoggerLog::warn("LoggerPropertyConfigurator::doConfigure() cannot load '$url' configuration."); 324 return false; 325 } 326 return $this->doConfigureProperties($properties, $repository); 327 } 328 329 330 /** 331 * Read configuration options from <b>properties</b>. 332 * 333 * @see doConfigure(). 334 * @param array $properties 335 * @param LoggerHierarchy &$hierarchy 336 */ 337 function doConfigureProperties($properties, &$hierarchy) 338 { 339 $value = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY]; 340 341 if (!empty($value)) { 342 LoggerLog::internalDebugging(LoggerOptionConverter::toBoolean($value, LoggerLog::internalDebugging())); 343 } 344 345 $thresholdStr = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX]; 346 $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll())); 347 348 $this->configureRootCategory($properties, $hierarchy); 349 $this->configureLoggerFactory($properties); 350 $this->parseCatsAndRenderers($properties, $hierarchy); 351 352 LoggerLog::debug("LoggerPropertyConfigurator::doConfigureProperties() Finished configuring."); 353 354 return true; 355 } 356 357 // -------------------------------------------------------------------------- 358 // Internal stuff 359 // -------------------------------------------------------------------------- 360 361 /** 362 * Check the provided <b>Properties</b> object for a 363 * {@link LoggerFactory} entry specified by 364 * {@link LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY}. 365 * 366 * If such an entry exists, an attempt is made to create an instance using 367 * the default constructor. 368 * This instance is used for subsequent Category creations 369 * within this configurator. 370 * 371 * @see parseCatsAndRenderers() 372 * @param array $props array of properties 373 */ 374 function configureLoggerFactory($props) 375 { 376 $factoryFqcn = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY]; 377 if(!empty($factoryFqcn)) { 378 $factoryClassName = basename($factoryFqcn); 379 LoggerLog::debug( 380 "LoggerPropertyConfigurator::configureLoggerFactory() Trying to load factory [" . 381 $factoryClassName . 382 "]." 383 ); 384 385 if (!class_exists($factoryClassName)) 386 @include_once("{$factoryFqcn}.php"); 387 if (class_exists($factoryClassName)) { 388 $loggerFactory = new $factoryClassName(); 389 } else { 390 LoggerLog::debug( 391 "LoggerPropertyConfigurator::configureLoggerFactory() Unable to load factory [" . 392 $factoryClassName . 393 "]. Using default." 394 ); 395 $loggerFactory = $this->loggerFactory; 396 } 397 398 LoggerLog::debug( 399 "LoggerPropertyConfigurator::configureLoggerFactory() ". 400 "Setting properties for category factory [" . get_class($loggerFactory) . "]." 401 ); 402 403 LoggerPropertySetter::setPropertiesByObject($loggerFactory, $props, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_FACTORY_PREFIX . "."); 404 } 405 } 406 407 /** 408 * @param array $props array of properties 409 * @param LoggerHierarchy &$hierarchy 410 */ 411 function configureRootCategory($props, &$hierarchy) 412 { 413 $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX; 414 $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX]; 415 416 if(empty($value)) { 417 $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX]; 418 $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX; 419 } 420 421 if (empty($value)) { 422 LoggerLog::debug( 423 "LoggerPropertyConfigurator::configureRootCategory() ". 424 "Could not find root logger information. Is this OK?" 425 ); 426 } else { 427 $root =& $hierarchy->getRootLogger(); 428 // synchronized(root) { 429 $this->parseCategory( 430 $props, 431 $root, 432 $effectivePrefix, 433 LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME, 434 $value 435 ); 436 // } 437 } 438 } 439 440 /** 441 * Parse non-root elements, such non-root categories and renderers. 442 * 443 * @param array $props array of properties 444 * @param LoggerHierarchy &$hierarchy 445 */ 446 function parseCatsAndRenderers($props, &$hierarchy) 447 { 448 while(list($key,$value) = each($props)) { 449 if( strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0 or 450 strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) { 451 if(strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0) { 452 $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX)); 453 } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) { 454 $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX)); 455 } 456 $logger =& $hierarchy->getLogger($loggerName, $this->loggerFactory); 457 // synchronized(logger) { 458 $this->parseCategory($props, $logger, $key, $loggerName, $value); 459 $this->parseAdditivityForLogger($props, $logger, $loggerName); 460 // } 461 } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX) === 0) { 462 $renderedClass = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX)); 463 $renderingClass = $value; 464 if (method_exists($hierarchy, 'addrenderer')) { 465 LoggerRendererMap::addRenderer($hierarchy, $renderedClass, $renderingClass); 466 } 467 } 468 } 469 } 470 471 /** 472 * Parse the additivity option for a non-root category. 473 * 474 * @param array $props array of properties 475 * @param Logger &$cat 476 * @param string $loggerName 477 */ 478 function parseAdditivityForLogger($props, &$cat, $loggerName) 479 { 480 $value = LoggerOptionConverter::findAndSubst( 481 LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName, 482 $props 483 ); 484 LoggerLog::debug( 485 "LoggerPropertyConfigurator::parseAdditivityForLogger() ". 486 "Handling " . LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName . "=[{$value}]" 487 ); 488 // touch additivity only if necessary 489 if(!empty($value)) { 490 $additivity = LoggerOptionConverter::toBoolean($value, true); 491 LoggerLog::debug( 492 "LoggerPropertyConfigurator::parseAdditivityForLogger() ". 493 "Setting additivity for [{$loggerName}] to [{$additivity}]" 494 ); 495 $cat->setAdditivity($additivity); 496 } 497 } 498 499 /** 500 * This method must work for the root category as well. 501 * 502 * @param array $props array of properties 503 * @param Logger &$logger 504 * @param string $optionKey 505 * @param string $loggerName 506 * @param string $value 507 * @return Logger 508 */ 509 function &parseCategory($props, &$logger, $optionKey, $loggerName, $value) 510 { 511 LoggerLog::debug( 512 "LoggerPropertyConfigurator::parseCategory() ". 513 "Parsing for [{$loggerName}] with value=[{$value}]." 514 ); 515 516 // We must skip over ',' but not white space 517 $st = explode(',', $value); 518 519 // If value is not in the form ", appender.." or "", then we should set 520 // the level of the loggeregory. 521 522 if(!(@$value{0} == ',' || empty($value))) { 523 // just to be on the safe side... 524 if(sizeof($st) == 0) 525 return; 526 527 $levelStr = current($st); 528 LoggerLog::debug( 529 "LoggerPropertyConfigurator::parseCategory() ". 530 "Level token is [$levelStr]." 531 ); 532 533 // If the level value is inherited, set category level value to 534 // null. We also check that the user has not specified inherited for the 535 // root category. 536 if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { 537 if ($loggerName == LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME) { 538 LoggerLog::warn( 539 "LoggerPropertyConfigurator::parseCategory() ". 540 "The root logger cannot be set to null." 541 ); 542 } else { 543 $logger->setLevel(null); 544 } 545 } else { 546 $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug())); 547 } 548 } 549 550 // Begin by removing all existing appenders. 551 $logger->removeAllAppenders(); 552 while($appenderName = next($st)) { 553 $appenderName = trim($appenderName); 554 if(empty($appenderName)) 555 continue; 556 LoggerLog::debug( 557 "LoggerPropertyConfigurator::parseCategory() ". 558 "Parsing appender named [{$appenderName}]." 559 ); 560 $appender =& $this->parseAppender($props, $appenderName); 561 if($appender !== null) { 562 $logger->addAppender($appender); 563 } 564 } 565 } 566 567 /** 568 * @param array $props array of properties 569 * @param string $appenderName 570 * @return LoggerAppender 571 */ 572 function &parseAppender($props, $appenderName) 573 { 574 $appender =& LoggerAppender::singleton($appenderName); 575 if($appender !== null) { 576 LoggerLog::debug( 577 "LoggerPropertyConfigurator::parseAppender() ". 578 "Appender [{$appenderName}] was already parsed." 579 ); 580 return $appender; 581 } 582 // Appender was not previously initialized. 583 $prefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX . $appenderName; 584 $layoutPrefix = $prefix . ".layout"; 585 $appenderClass = @$props[$prefix]; 586 if (!empty($appenderClass)) { 587 $appender =& LoggerAppender::singleton($appenderName, $appenderClass); 588 if($appender === null) { 589 LoggerLog::warn( 590 "LoggerPropertyConfigurator::parseAppender() ". 591 "Could not instantiate appender named [$appenderName]." 592 ); 593 return null; 594 } 595 } else { 596 LoggerLog::warn( 597 "LoggerPropertyConfigurator::parseAppender() ". 598 "Could not instantiate appender named [$appenderName] with null className." 599 ); 600 return null; 601 } 602 603 $appender->setName($appenderName); 604 if( $appender->requiresLayout() ) { 605 LoggerLog::debug( 606 "LoggerPropertyConfigurator::parseAppender() ". 607 "Parsing layout section for [$appenderName]." 608 ); 609 $layoutClass = @$props[$layoutPrefix]; 610 $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); 611 if (empty($layoutClass)) { 612 LoggerLog::warn( 613 "LoggerPropertyConfigurator::parseAppender() ". 614 "layout class is empty in '$layoutPrefix'. Using Simple layout" 615 ); 616 $layout = LoggerLayout::factory('LoggerLayoutSimple'); 617 } else { 618 $layout = LoggerLayout::factory($layoutClass); 619 620 if($layout === null) { 621 LoggerLog::warn( 622 "LoggerPropertyConfigurator::parseAppender() ". 623 "cannot create layout '$layoutClass'. Using Simple layout" 624 ); 625 $layout = LoggerLayout::factory('LoggerLayoutSimple'); 626 } 627 } 628 629 LoggerLog::debug( 630 "LoggerPropertyConfigurator::parseAppender() ". 631 "Parsing layout options for [$appenderName]." 632 ); 633 LoggerPropertySetter::setPropertiesByObject($layout, $props, $layoutPrefix . "."); 634 LoggerLog::debug( 635 "LoggerPropertyConfigurator::parseAppender() ". 636 "End Parsing layout options for [$appenderName]." 637 ); 638 $appender->setLayout($layout); 639 640 } 641 LoggerPropertySetter::setPropertiesByObject($appender, $props, $prefix . "."); 642 LoggerLog::debug( 643 "LoggerPropertyConfigurator::parseAppender() ". 644 "Parsed [{$appenderName}] options." 645 ); 646 return $appender; 647 } 648 649 } 650 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |