/** * test epLog */ function testLog() { // load config.xml $log_cfg =& epConfig::load(realpath(dirname(__FILE__)) . "/input/config.xml"); $this->assertTrue(!empty($log_cfg)); // make log file absolute path $log_file = realpath(dirname(__FILE__)) . "/output/test.log"; // delete it first so it won't accumulate and become a huge file @unlink($log_file); $this->assertTrue($log_cfg->set('log_file', $log_file)); $this->assertTrue($log_file == $log_cfg->get('log_file')); // config log with the log section only $logger =& epLog::instance(); $this->assertTrue($logger); $logger->setConfig($log_cfg); // generate all messages $msgs = array(); for ($i = 0; $i < 10; $i++) { $msg = 'log test message id (' . rand(0, 100000) . ') at ' . date('H:i:s'); $msgs[] = $msg; } // log all messages foreach ($msgs as $msg) { $status = $logger->log($msg); $this->assertTrue($status); } // figure out the log file $log_file = $logger->getConfigOption('log_file'); $this->assertTrue(file_exists($log_file)); // check if the messages are in the log file $content = file_get_contents($log_file); $this->assertTrue(!empty($content)); foreach ($msgs as $msg) { $this->assertTrue(strstr($content, $content) != false); } }
/** * Set logger config * @return bool * @see epLog */ protected function _setLogConfig() { // check logger instance if (!$this->logger) { if (!($logger =& epLog::instance())) { throw new epExceptionConfigurableWithLog('Cannot instantiate logger'); return false; } } // set log config $this->logger->setConfig($this->getConfig()); // something wrong return false; }
/** * Implement {@link epSingleton} interface * Forcefully destroy old instance (only used for tests). * After reset(), {@link instance()} returns a new instance. */ public static function destroy() { self::$instance = null; }