Last change
on this file since 1256 was
523,
checked in by rlacroix, 10 years ago
|
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.
|
-
Property copyright set to
Software name : XIOS (Xml I/O Server) http://forge.ipsl.jussieu.fr/ioserver Creation date : January 2009 Licence : CeCCIL version2 see license file in root directory : Licence_CeCILL_V2-en.txt or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement) CNRS/IPSL (Institut Pierre Simon Laplace) Project Manager : Yann Meurdesoif yann.meurdesoif@cea.fr
|
File size:
1.5 KB
|
Rev | Line | |
---|
[380] | 1 | #ifndef __XIOS_LOG_HPP__ |
---|
| 2 | #define __XIOS_LOG_HPP__ |
---|
[300] | 3 | |
---|
[364] | 4 | #include <string> |
---|
[300] | 5 | #include <iostream> |
---|
[369] | 6 | #include <string> |
---|
[300] | 7 | |
---|
[335] | 8 | namespace xios |
---|
[300] | 9 | { |
---|
| 10 | using namespace std ; |
---|
| 11 | |
---|
| 12 | class CLog : public ostream |
---|
| 13 | { |
---|
| 14 | public : |
---|
[523] | 15 | CLog(const string& name_, std::streambuf* sBuff = cout.rdbuf()) |
---|
| 16 | : ostream(sBuff), level(0), name(name_), strBuf_(sBuff) {} |
---|
[490] | 17 | CLog& operator()(int l) |
---|
| 18 | { |
---|
| 19 | if (l<=level) |
---|
[300] | 20 | { |
---|
[490] | 21 | rdbuf(strBuf_); |
---|
[347] | 22 | *this<<"-> "<<name<<" : " ; |
---|
[300] | 23 | } |
---|
| 24 | else rdbuf(NULL) ; |
---|
| 25 | return *this; |
---|
| 26 | } |
---|
[490] | 27 | void setLevel(int l) {level=l; } |
---|
[300] | 28 | int getLevel() {return level ;} |
---|
| 29 | bool isActive(void) { if (rdbuf()==NULL) return true ; else return false ;} |
---|
| 30 | bool isActive(int l) {if (l<=level) return true ; else return false ; } |
---|
| 31 | |
---|
[490] | 32 | public: |
---|
[523] | 33 | //! Write log into a file with its streambuf |
---|
[490] | 34 | void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); } |
---|
| 35 | |
---|
[523] | 36 | //! Write log into standard output |
---|
[490] | 37 | void write2StdOut() { changeStreamBuff(cout.rdbuf()); } |
---|
[523] | 38 | |
---|
| 39 | //! Write log into standard error output |
---|
| 40 | void write2StdErr() { changeStreamBuff(cerr.rdbuf()); } |
---|
| 41 | |
---|
[490] | 42 | private: |
---|
| 43 | /*! |
---|
| 44 | * \brief Change current streambuf (by default std::cout) to new one |
---|
| 45 | * This function associates a new streambuf to the current log object |
---|
| 46 | * \param [in] pointer to new streambuf |
---|
| 47 | */ |
---|
| 48 | void changeStreamBuff(std::streambuf* sBuff) { strBuf_ = sBuff; rdbuf(sBuff); } |
---|
| 49 | |
---|
[300] | 50 | int level ; |
---|
[347] | 51 | string name ; |
---|
[490] | 52 | std::streambuf* strBuf_; |
---|
[300] | 53 | }; |
---|
| 54 | |
---|
| 55 | extern CLog info; |
---|
[347] | 56 | extern CLog report; |
---|
[523] | 57 | extern CLog error; |
---|
[300] | 58 | } |
---|
| 59 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.