Example #1
0
 public function testCheckLogMessages()
 {
     $fileRelPath = '/bitrix/tmp/obx.core/test_log_file.log';
     $filePath = self::$_docRoot . '/bitrix/tmp/obx.core/test_log_file.log';
     @unlink($filePath);
     $LogFile = new LogFile(__METHOD__, $fileRelPath, 'w');
     for ($i = 0; $i <= 20; $i++) {
         if ($i == 7) {
             $LogFile->setDefaultMessageType(LogFile::MSG_TYPE_WARNING);
         }
         if ($i == 14) {
             $LogFile->setDefaultMessageType(LogFile::MSG_TYPE_NOTE);
         }
         $LogFile->logMessage('test message marker#' . $i);
     }
     $this->assertFileExists($filePath);
     $fileContent = file_get_contents($filePath);
     for ($i = 0; $i <= 20; $i++) {
         $prefix = '';
         if ($i < 14) {
             $prefix = 'Warning: ';
         }
         if ($i < 7) {
             $prefix = 'Error: ';
         }
         $this->assertTrue(false !== strpos($fileContent, $prefix . 'test message marker#' . $i));
     }
     @unlink($filePath);
 }
Example #2
0
 public function addError($text, $code = 0)
 {
     $this->_arCommonMessagePool[$this->_countCommonMessages] = array("TEXT" => $text, "CODE" => $code, "TYPE" => "E");
     $this->_arErrors[$this->_countErrors] =& $this->_arCommonMessagePool[$this->_countCommonMessages];
     $this->_countErrors++;
     $this->_countCommonMessages++;
     if ($this->_LogFile && ($this->_logBehaviour & self::MSG_POOL_LOG_ERRORS) > 0) {
         $this->_LogFile->logMessage($text . (!empty($code) ? '. Error code: ' . $code : ''), LogFile::MSG_TYPE_ERROR);
     }
 }