Changeset 562
- Timestamp:
- 04/19/07 17:19:35 (2 years ago)
- Files:
-
- trunk/src/main/php/net/stubbles/util/log/stubFileLogAppender.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/util/log/stubLogAppender.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/util/log/stubLogData.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/util/log/stubLogPreInterceptor.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/util/log/stubLogger.php (modified) (13 diffs)
- trunk/src/main/php/net/stubbles/util/log/stubLoggerXJConfFactory.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/integration/LoggerTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/UtilTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/errorhandler/stubLogErrorHandlerTestCase.php (modified) (8 diffs)
- trunk/src/test/php/net/stubbles/util/log/stubLoggerTestCase.php (modified) (7 diffs)
- trunk/src/test/php/net/stubbles/util/log/stubLoggerXJConfFactoryTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/util/log/stubFileLogAppender.php
r400 r562 27 27 */ 28 28 protected $logDir = ''; 29 29 30 30 /** 31 31 * constructor 32 32 * 33 * @param string $logDir the directory to write the logfiles into33 * @param string $logDir optional the directory to write the logfiles into 34 34 */ 35 public function __construct($logDir )35 public function __construct($logDir = null) 36 36 { 37 if (null == $logDir) { 38 $logDir = stubConfig::getLogPath(); 39 } 40 37 41 $this->setLogDir($logDir); 38 42 } 39 43 44 /** 45 * sets the configuration data 46 * 47 * @param array $config 48 */ 49 public function setConfig(array $config) 50 { 51 // intentionally empty 52 } 53 54 /** 55 * returns the configuration 56 * 57 * @return array 58 */ 59 public function getConfig() 60 { 61 return array(); 62 } 63 40 64 /** 41 65 * set the logpath … … 51 75 $this->logDir = $logDir; 52 76 } 53 77 54 78 /** 55 79 * returns the logpath … … 61 85 return $this->logDir; 62 86 } 63 87 64 88 /** 65 89 * builds the log directory … … 71 95 return str_replace('{Y}', date('Y'), str_replace('{M}', date('m'), $this->logDir)); 72 96 } 73 97 74 98 /** 75 99 * append the log data to the log target … … 89 113 error_log($logData->get() . "\n", 3, $logDir . '/' . $logData->getTarget() . '-' . date('Y-m-d') . '.log'); 90 114 } 91 115 92 116 /** 93 117 * finalize the log target trunk/src/main/php/net/stubbles/util/log/stubLogAppender.php
r373 r562 17 17 * @subpackage util_log 18 18 */ 19 interface stubLogAppender 19 interface stubLogAppender extends stubObject 20 20 { 21 /** 22 * sets the configuration data 23 * 24 * @param array $config 25 */ 26 public function setConfig(array $config); 27 28 /** 29 * returns the configuration 30 * 31 * @return array 32 */ 33 public function getConfig(); 34 21 35 /** 22 36 * append the log data to the log target … … 25 39 */ 26 40 public function append(stubLogData $logData); 27 41 28 42 /** 29 43 * finalize the log target trunk/src/main/php/net/stubbles/util/log/stubLogData.php
r146 r562 15 15 * @subpackage util_log 16 16 */ 17 interface stubLogData 17 interface stubLogData extends stubObject 18 18 { 19 19 /** … … 21 21 */ 22 22 const SEPERATOR = '|'; 23 23 24 24 /** 25 25 * adds data to the log object … … 30 30 */ 31 31 public function addData($data); 32 32 33 33 /** 34 34 * returns the whole log data as one line … … 37 37 */ 38 38 public function get(); 39 39 40 40 /** 41 41 * returns the level of the log data … … 45 45 */ 46 46 public function getLevel(); 47 47 48 48 /** 49 49 * returns the target where the log data should go to trunk/src/main/php/net/stubbles/util/log/stubLogPreInterceptor.php
r473 r562 25 25 public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) 26 26 { 27 stubLoggerXJConfFactory::init(stubConfig::getConfigPath() . '/xml/logging.xml'); 27 $loggerXJConFactory = new stubLoggerXJConfFactory(); 28 $loggerXJConFactory->init(); 28 29 } 29 30 } trunk/src/main/php/net/stubbles/util/log/stubLogger.php
r400 r562 78 78 */ 79 79 protected $logAppender = array(); 80 80 81 81 /** 82 82 * constructor … … 92 92 $this->level = $level; 93 93 } 94 94 95 95 /** 96 96 * destructor … … 104 104 } 105 105 } 106 106 107 107 /** 108 108 * returns a logger instance … … 125 125 return self::$instances[$id]; 126 126 } 127 127 128 128 /** 129 129 * returns a list of existing instances … … 135 135 return array_keys(self::$instances); 136 136 } 137 137 138 138 /** 139 139 * destroys the logger with the given id … … 145 145 if (isset(self::$instances[$id]) == true) { 146 146 self::$instances[$id] = null; 147 } 148 } 149 147 unset(self::$instances[$id]); 148 } 149 } 150 150 151 /** 151 152 * clone is not supported … … 155 156 throw new stubLoggerException('Cloning a logger is not allowed.'); 156 157 } 157 158 158 159 /** 159 160 * returns the id of the logger … … 165 166 return $this->id; 166 167 } 167 168 168 169 /** 169 170 * returns the level where the logger is applicable for … … 175 176 return $this->level; 176 177 } 177 178 178 179 /** 179 180 * checks whether the logger is applicable for the given level … … 190 191 return (($this->level & $level) != 0); 191 192 } 192 193 193 194 /** 194 195 * adds a log appender to the logger … … 202 203 $this->logAppender[] = $logAppender; 203 204 } 204 205 205 206 /** 206 207 * returns a list of log appenders appended to the logger … … 212 213 return $this->logAppender; 213 214 } 214 215 215 216 /** 216 217 * log data to all loggers created … … 228 229 } 229 230 } 230 231 231 232 /** 232 233 * sends log data to all registered log appenders trunk/src/main/php/net/stubbles/util/log/stubLoggerXJConfFactory.php
r443 r562 7 7 * @subpackage util_log 8 8 */ 9 stubClassLoader::load('net.stubbles.util. stubFactory',9 stubClassLoader::load('net.stubbles.util.log.stubLogger', 10 10 'net.stubbles.util.xjconf.xjconf' 11 11 ); … … 18 18 * @uses http://php.xjconf.net/ 19 19 */ 20 class stubLoggerXJConfFactory 20 class stubLoggerXJConfFactory extends stubBaseObject implements stubXJConfInitializer 21 21 { 22 22 /** 23 * initialize the stubLogger with configuration values from given configuration file23 * returns the descriptor that identifies this initializer 24 24 * 25 * @param string $configFile 25 * @return string 26 */ 27 public function getDescriptor() 28 { 29 return 'logging'; 30 } 31 32 /** 33 * returns the data to cache 34 * 35 * @return array 36 */ 37 public function getCacheData() 38 { 39 $cacheData = array(); 40 $loggerIds = stubLogger::getInstanceList(); 41 foreach ($loggerIds as $loggerId) { 42 $logger = stubLogger::getInstance($loggerId); 43 $cacheData[$loggerId] = array('level' => $logger->getLevel(), 44 'appender' => array() 45 ); 46 foreach ($logger->getLogAppenders() as $logAppender) { 47 $cacheData[$loggerId]['appender'][$logAppender->getClassname()] = $logAppender->getConfig(); 48 } 49 } 50 51 return $cacheData; 52 } 53 54 /** 55 * sets the data from the cache 56 * 57 * @param array $cacheData 58 */ 59 public function setCacheData(array $cacheData) 60 { 61 foreach ($cacheData as $loggerId => $loggerConfig) { 62 $logger = stubLogger::getInstance($loggerId, $loggerConfig['level']); 63 foreach ($loggerConfig['appender'] as $logAppenderClassName => $logAppenderConfig) { 64 $nqClassName = stubClassLoader::getNonQualifiedClassName($logAppenderClassName); 65 if (class_exists($nqClassName, false) == false) { 66 stubClassLoader::load($logAppenderClassName); 67 } 68 69 $logAppender = new $nqClassName(); 70 $logAppender->setConfig($logAppenderConfig); 71 $logger->addLogAppender($logAppender); 72 } 73 } 74 } 75 76 /** 77 * will be called in case the stubXJConfProxy did not found the data in the 78 * cache and the initializer has to load values from the facade 79 * 80 * @param stubXJConfFacade $xjconf 81 */ 82 public function loadData(stubXJConfFacade $xjconf) 83 { 84 // intentionally empty, all stubLogger instances are inside a static member of stubLogger 85 } 86 87 /** 88 * initialize the stubLogger 89 * 26 90 * @throws stubXJConfException 27 91 */ 28 public static function init($configFile)92 public function init() 29 93 { 30 $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 31 $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/logging.xml')); 32 $configExtension = new stubConfigXJConfExtension(); 33 $xjconf->addExtension($configExtension); 34 $xjconf->enableXIncludes(); 35 $xjconf->parse($configFile); 94 $xjconfProxy = new stubXJConfProxy($this); 95 $xjconfProxy->process(array(new stubConfigXJConfExtension())); 36 96 } 37 97 } trunk/src/main/php/net/stubbles/util/xjconf/stubXJConfProxy.php
r538 r562 62 62 * initialize with configuration values from given configuration file 63 63 * 64 * @return bool true if data was cached, else false 64 * @param array<Extension> a list of XJConf extensions 65 * @return bool true if data was cached, else false 65 66 * @throws stubXJConfException 66 67 */ 67 public function process( )68 public function process(array $extensions = array()) 68 69 { 69 70 if (file_exists($this->cacheFile) == true && filemtime($this->cacheFile) >= filemtime($this->configFile)) { … … 75 76 $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/' . $this->initializer->getDescriptor() . '.xml')); 76 77 $xjconf->enableXIncludes(); 78 foreach ($extensions as $extension) { 79 $xjconf->addExtension($extension); 80 } 81 77 82 $xjconf->parse($this->configFile); 78 83 $this->initializer->loadData($xjconf); trunk/src/test/php/net/stubbles/integration/LoggerTestCase.php
r400 r562 17 17 { 18 18 /** 19 * clean up test environment 20 */ 21 public function tearDown() 22 { 23 $loggerIds = stubLogger::getInstanceList(); 24 foreach ($loggerIds as $loggerId) { 25 stubLogger::destroyInstance($loggerId); 26 } 27 } 28 29 /** 19 30 * assure that creating the logger instances works correct 20 31 */ 21 32 public function testLoggerXJConfFactory() 22 33 { 23 stubLoggerXJConfFactory::init(stubConfig::getConfigPath() . '/xml/logging.xml'); 34 $loggerXJConfFactory = new stubLoggerXJConfFactory(); 35 $loggerXJConfFactory->init(); 24 36 $this->assertEqual(stubLogger::getInstanceList(), array(stubLogger::DEFAULT_ID)); 25 37 $logger = stubLogger::getInstance(); trunk/src/test/php/net/stubbles/util/UtilTestSuite.php
r538 r562 39 39 $this->addTestFile($dir . '/log/stubBaseLogDataTestCase.php'); 40 40 $this->addTestFile($dir . '/log/stubLogDataFactoryTestCase.php'); 41 $this->addTestFile($dir . '/log/stubLoggerXJConfFactoryTestCase.php'); 41 42 42 43 // now all the validators trunk/src/test/php/net/stubbles/util/errorhandler/stubLogErrorHandlerTestCase.php
r422 r562 9 9 stubClassLoader::load('net.stubbles.util.errorhandler.stubLogErrorHandler'); 10 10 Mock::generate('stubSession'); 11 class stubTestLogAppender implements stubLogAppender11 class stubTestLogAppender extends stubBaseObject implements stubLogAppender 12 12 { 13 13 protected $logData = array(); 14 14 15 public function setConfig(array $config) { } 16 17 public function getConfig() 18 { 19 return array(); 20 } 21 15 22 public function append(stubLogData $logData) 16 23 { 17 24 $this->logData[] = $logData; 18 25 } 19 26 20 27 public function getLogData() 21 28 { 22 29 return $this->logData; 23 30 } 24 31 25 32 public function finalize() {} 26 33 } … … 39 46 */ 40 47 protected $logErrorHandler; 41 48 42 49 /** 43 50 * set up test environment … … 48 55 stubRegistry::setConfig('net.stubbles.util.log.class', 'net.stubbles.util.log.stubBaseLogData'); 49 56 } 50 57 58 /** 59 * clean up test environment 60 */ 61 public function tearDown() 62 { 63 $loggerIds = stubLogger::getInstanceList(); 64 foreach ($loggerIds as $loggerId) { 65 stubLogger::destroyInstance($loggerId); 66 } 67 } 68 51 69 /** 52 70 * test that event listener is removed if it has a session … … 59 77 $this->assertTrue($this->logErrorHandler->autoremove()); 60 78 } 61 79 62 80 /** 63 81 * assure that isResponsible() works correct … … 67 85 $this->assertTrue($this->logErrorHandler->isResponsible(E_NOTICE, 'foo')); 68 86 } 69 87 70 88 /** 71 89 * assure that isSupressable() works correct … … 75 93 $this->assertFalse($this->logErrorHandler->isSupressable(E_NOTICE, 'foo')); 76 94 } 77 95 78 96 /** 79 97 * assure that the error is put onto a stack of the session is set … … 91 109 ); 92 110 } 93 111 94 112 /** 95 113 * assure that the error is logged if the session is set … … 118 136 stubLogger::destroyInstance(__CLASS__); 119 137 } 120 138 121 139 /** 122 140 * assure that the error is logged after the session is set trunk/src/test/php/net/stubbles/util/log/stubLoggerTestCase.php
r146 r562 24 24 */ 25 25 protected $stubLogger; 26 26 27 27 /** 28 28 * set up the test environment … … 32 32 $this->stubLogger = stubLogger::getInstance(); 33 33 } 34 34 35 35 /** 36 36 * clean up test environment … … 38 38 public function tearDown() 39 39 { 40 stubLogger::destroyInstance(stubLogger::DEFAULT_ID); 41 } 42 40 $loggerIds = stubLogger::getInstanceList(); 41 foreach ($loggerIds as $loggerId) { 42 stubLogger::destroyInstance($loggerId); 43 } 44 } 45 43 46 /** 44 47 * assure that creation of loggers works as expected … … 51 54 $this->assertReference($this->stubLogger, $stubLogger); 52 55 } 53 56 54 57 /** 55 58 * assert that level handling is coorect … … 164 167 stubLogger::destroyInstance('warnerror'); 165 168 } 166 169 167 170 /** 168 171 * test the instance logging method … … 179 182 $this->stubLogger->log($mockLogData); 180 183 } 181 184 182 185 /** 183 186 * test the static logging method … … 207 210 stubLogger::destroyInstance('warn'); 208 211 } 212 213 /** 214 * assure that instances are really destroyed 215 */ 216 public function testDestroy() 217 { 218 $loggerTest = stubLogger::getInstance('test'); 219 stubLogger::destroyInstance('test'); 220 $this->assertFalse(in_array('test', stubLogger::getInstanceList())); 221 } 209 222 } 210 223 ?>
