Exemple #1
0
 /**
  * Builds the log file entry for the given log message.
  *
  * TODO: Use localized time in local log files
  *
  * @param string $logLevel Log level of the message to log
  * @param string $message The message to log
  * @param \Exception|null $exception Exception belonging to the log entry
  * @return string
  */
 private function buildLogEntry(string $logLevel, string $message, Exception $exception = null)
 {
     // build base log entry
     $logEntry = sprintf('%s %s %s', DateUtil::getCurrentUtcDateTime()->format('Y-m-d H:i:s'), StringUtil::toUpperCase($logLevel), $message);
     // add exception information if present
     if ($exception !== null) {
         $logEntry .= StringUtil::CHAR_LINE_FEED . sprintf('Exception: %s in file %s on line %s', $exception->getMessage(), $exception->getFile(), $exception->getLine()) . StringUtil::CHAR_LINE_FEED . ExceptionUtil::getFullTrace($exception);
     }
     // return log entry
     return $logEntry;
 }
 /**
  * Tests whether getFullTrace() works as expected.
  */
 public function testGetFullTrace()
 {
     $root = new SystemException('root', 1, E_USER_WARNING, '/path/file10', 10);
     $parent1 = new \Exception('parent1', 2, $root);
     $parent2 = new SystemException('parent2', 3, E_USER_NOTICE, '/path/file12', 12, $parent1);
     $parent3 = new \ErrorException('parent3', 4, E_WARNING, '/path/file13', 13, $parent2);
     $parent4 = new SystemException('parent4', 5, E_WARNING, '/path/file14', 14, $parent3);
     $trace = ExceptionUtil::getFullTrace($parent4);
     $this->assertContains('Previous: parent3 in file /path/file13 on line 13', $trace);
     $this->assertContains('Previous: parent2 in file /path/file12 on line 12', $trace);
     $this->assertContains('Previous: parent1 in file ', $trace);
     $this->assertContains('Previous: root in file /path/file10 on line 10', $trace);
 }