|
Last change
on this file since 3848 was
3848,
checked in by ymipsl, 10 years ago
|
|
Add XIOS in Aquaplanet configuration.
YM
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | #ifndef __XIOS_LOG_HPP__ |
|---|
| 2 | #define __XIOS_LOG_HPP__ |
|---|
| 3 | |
|---|
| 4 | #include <string> |
|---|
| 5 | #include <iostream> |
|---|
| 6 | #include <string> |
|---|
| 7 | |
|---|
| 8 | namespace xios |
|---|
| 9 | { |
|---|
| 10 | using namespace std ; |
|---|
| 11 | |
|---|
| 12 | class CLog : public ostream |
|---|
| 13 | { |
|---|
| 14 | public : |
|---|
| 15 | CLog(const string& name_, std::streambuf* sBuff = cout.rdbuf()) |
|---|
| 16 | : ostream(sBuff), level(0), name(name_), strBuf_(sBuff) {} |
|---|
| 17 | CLog& operator()(int l) |
|---|
| 18 | { |
|---|
| 19 | if (l<=level) |
|---|
| 20 | { |
|---|
| 21 | rdbuf(strBuf_); |
|---|
| 22 | *this<<"-> "<<name<<" : " ; |
|---|
| 23 | } |
|---|
| 24 | else rdbuf(NULL) ; |
|---|
| 25 | return *this; |
|---|
| 26 | } |
|---|
| 27 | void setLevel(int l) {level=l; } |
|---|
| 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 | |
|---|
| 32 | public: |
|---|
| 33 | //! Write log into a file with its streambuf |
|---|
| 34 | void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); } |
|---|
| 35 | |
|---|
| 36 | //! Write log into standard output |
|---|
| 37 | void write2StdOut() { changeStreamBuff(cout.rdbuf()); } |
|---|
| 38 | |
|---|
| 39 | //! Write log into standard error output |
|---|
| 40 | void write2StdErr() { changeStreamBuff(cerr.rdbuf()); } |
|---|
| 41 | |
|---|
| 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 | |
|---|
| 50 | int level ; |
|---|
| 51 | string name ; |
|---|
| 52 | std::streambuf* strBuf_; |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | extern CLog info; |
|---|
| 56 | extern CLog report; |
|---|
| 57 | extern CLog error; |
|---|
| 58 | } |
|---|
| 59 | #endif |
|---|
Note: See
TracBrowser
for help on using the repository browser.