Ignore:
Timestamp:
12/01/14 16:21:48 (10 years ago)
Author:
rlacroix
Message:

Improve the message error handling by mimicking the behavior of the info/report logs.

Output the error messages to the standart error message until the context is correctly initialized. Then, output the error messages to a file if the user has set "print_file" parameter to "true".

  • Fix: Errors that occured before MPI was initialized (e.g. during the config file parsing) caused a MPI error on top of the original error.
  • Fix: The error file could sometimes be misnamed if the error happened before the context was completely known.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/server.cpp

    r501 r523  
    2121    int CServer::rank = INVALID_RANK; 
    2222    StdOFStream CServer::m_infoStream; 
     23    StdOFStream CServer::m_errorStream; 
    2324    map<string,CContext*> CServer::contextList ; 
    2425    bool CServer::finished=false ; 
     
    407408     } 
    408409 
    409      /*! 
    410       * \brief Open file stream to write in 
    411       *   Opening a file stream with a specific file name suffix-server+rank 
    412       * \param [in] protype file name 
    413      */ 
    414      void CServer::openInfoStream(const StdString& fileName) 
    415      { 
    416        std::filebuf* fb = m_infoStream.rdbuf(); 
    417        StdStringStream fileNameServer; 
    418        int numDigit = 0; 
    419        int size = 0; 
    420        MPI_Comm_size(CXios::globalComm, &size); 
    421        while (size) 
    422        { 
    423          size /= 10; 
    424          ++numDigit; 
    425        } 
    426  
    427        fileNameServer << fileName <<"_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out"; 
    428        fb->open(fileNameServer.str().c_str(), std::ios::out); 
    429        if (!fb->is_open()) 
    430        ERROR("void CServer::openInfoStream(const StdString& fileName)", 
    431             <<endl<< "Can not open <"<<fileNameServer<<"> file to write" ); 
    432  
    433        info.write2File(fb); 
    434        report.write2File(fb); 
    435      } 
    436  
    437      //! Open stream for standard output 
    438      void CServer::openInfoStream() 
    439      { 
    440        info.write2StdOut(); 
    441        report.write2StdOut(); 
    442      } 
    443  
    444      //! Close opening stream 
    445      void CServer::closeInfoStream() 
    446      { 
    447        if (m_infoStream.is_open()) m_infoStream.close(); 
    448      } 
    449  
     410    /*! 
     411    * Open a file specified by a suffix and an extension and use it for the given file buffer. 
     412    * The file name will be suffix+rank+extension. 
     413    *  
     414    * \param fileName[in] protype file name 
     415    * \param ext [in] extension of the file 
     416    * \param fb [in/out] the file buffer 
     417    */ 
     418    void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb) 
     419    { 
     420      StdStringStream fileNameClient; 
     421      int numDigit = 0; 
     422      int size = 0; 
     423      MPI_Comm_size(CXios::globalComm, &size); 
     424      while (size) 
     425      { 
     426        size /= 10; 
     427        ++numDigit; 
     428      } 
     429 
     430      fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 
     431      fb->open(fileNameClient.str().c_str(), std::ios::out); 
     432      if (!fb->is_open()) 
     433        ERROR("void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", 
     434              << std::endl << "Can not open <" << fileNameClient << "> file to write the server log(s)."); 
     435    } 
     436 
     437    /*! 
     438    * \brief Open a file stream to write the info logs 
     439    * Open a file stream with a specific file name suffix+rank 
     440    * to write the info logs. 
     441    * \param fileName [in] protype file name 
     442    */ 
     443    void CServer::openInfoStream(const StdString& fileName) 
     444    { 
     445      std::filebuf* fb = m_infoStream.rdbuf(); 
     446      openStream(fileName, ".out", fb); 
     447 
     448      info.write2File(fb); 
     449      report.write2File(fb); 
     450    } 
     451 
     452    //! Write the info logs to standard output 
     453    void CServer::openInfoStream() 
     454    { 
     455      info.write2StdOut(); 
     456      report.write2StdOut(); 
     457    } 
     458 
     459    //! Close the info logs file if it opens 
     460    void CServer::closeInfoStream() 
     461    { 
     462      if (m_infoStream.is_open()) m_infoStream.close(); 
     463    } 
     464 
     465    /*! 
     466    * \brief Open a file stream to write the error log 
     467    * Open a file stream with a specific file name suffix+rank 
     468    * to write the error log. 
     469    * \param fileName [in] protype file name 
     470    */ 
     471    void CServer::openErrorStream(const StdString& fileName) 
     472    { 
     473      std::filebuf* fb = m_errorStream.rdbuf(); 
     474      openStream(fileName, ".err", fb); 
     475 
     476      error.write2File(fb); 
     477    } 
     478 
     479    //! Write the error log to standard error output 
     480    void CServer::openErrorStream() 
     481    { 
     482      error.write2StdErr(); 
     483    } 
     484 
     485    //! Close the error log file if it opens 
     486    void CServer::closeErrorStream() 
     487    { 
     488      if (m_errorStream.is_open()) m_errorStream.close(); 
     489    } 
    450490} 
Note: See TracChangeset for help on using the changeset viewer.