示例#1
0
 /**
  * Main entry point into the application.
  *
  * @return void
  */
 public function main()
 {
     $runner = new DocBlox_Task_Runner($_SERVER['argc'] == 1 ? false : $_SERVER['argv'][1], 'project:run');
     $task = $runner->getTask();
     $threshold = DocBlox_Core_Log::WARN;
     if (!$task->getQuiet()) {
         DocBlox_Core_Application::renderVersion();
     } else {
         $threshold = DocBlox_Core_Log::QUIET;
     }
     if ($task->getVerbose()) {
         $threshold = DocBlox_Core_Log::DEBUG;
     }
     $dispatcher = new sfEventDispatcher();
     $logger = new DocBlox_Core_Log(DocBlox_Core_Log::FILE_STDOUT);
     $logger->setThreshold($threshold);
     $dispatcher->connect('system.log', array($logger, 'log'));
     DocBlox_Parser_Abstract::$event_dispatcher = $dispatcher;
     DocBlox_Transformer_Abstract::$event_dispatcher = $dispatcher;
     DocBlox_Reflection_Abstract::$event_dispatcher = $dispatcher;
     try {
         $task->execute();
     } catch (Exception $e) {
         if (!$task->getQuiet()) {
             echo 'ERROR: ' . $e->getMessage() . PHP_EOL . PHP_EOL;
             echo $task->getUsageMessage();
         }
         die(1);
     }
 }
示例#2
0
 public function testLog()
 {
     if (file_exists('/tmp/DocBlox_Core_Log_test')) {
         unlink('/tmp/DocBlox_Core_Log_test');
     }
     $this->fixture = new DocBlox_Core_Log('/tmp/DocBlox_Core_Log_test');
     $this->fixture->setThreshold(DocBlox_Core_Log::ERR);
     $this->fixture->log('test', DocBlox_Core_Log::ERR);
     $this->fixture->log('test2', DocBlox_Core_Log::INFO);
     $result = file_get_contents('/tmp/DocBlox_Core_Log_test');
     $this->assertNotEmpty($result);
     $this->assertContains('test', $result);
     $this->assertNotContains('mb]:', $result, 'Should not contain debug information');
     $this->assertNotContains('test2', $result, 'Should not contain test2 as it is of a lower level');
     $this->fixture->setThreshold(DocBlox_Core_Log::DEBUG);
     $this->fixture->log('test3', DocBlox_Core_Log::INFO);
     $result = file_get_contents('/tmp/DocBlox_Core_Log_test');
     $this->assertContains('test3', $result);
     $this->assertContains('mb]:', $result, 'Should contain debug information when threshold is DEBUG');
     $this->fixture->log(array('test4'), DocBlox_Core_Log::INFO);
     $result = file_get_contents('/tmp/DocBlox_Core_Log_test');
     $this->assertContains('array', $result, 'The log should contain a var_dumped output');
 }
示例#3
0
 /**
  * Logs the message to the log with the given priority.
  *
  * This method only works if the Log Level is higher than the given priority.
  * If there is no logger object than this method will instantiate it.
  * In contrary to the debug statement this only logs strings.
  *
  * @param string $message  Element to log.
  * @param int    $priority Priority of the given log.
  *
  * @see DocBlock_Abstract::setLogLevel()
  * @see Zend_Log
  *
  * @return void
  */
 public function log($message, $priority = DocBlox_Core_Log::INFO)
 {
     if ($priority == DocBlox_Core_Log::DEBUG) {
         $this->debug($message);
         return;
     }
     if (!self::$logger || !self::$stdout_logger) {
         $config = $this->getConfig();
         // log to file
         self::$logger = new DocBlox_Core_Log($config->logging->paths->default);
         self::$logger->setThreshold($this->getLogLevel());
         // log to stdout
         self::$stdout_logger = new DocBlox_Core_Log(DocBlox_Core_Log::FILE_STDOUT);
         self::$stdout_logger->setThreshold($this->getLogLevel());
     }
     self::$logger->log($message, $priority);
     self::$stdout_logger->log($message, $priority);
 }