Last change
on this file since 2361 was
1601,
checked in by yushan, 6 years ago
|
branch_openmp merged with trunk r1597
|
-
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.7 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> |
---|
[1601] | 7 | #include <stdio.h> |
---|
| 8 | #include <omp.h> |
---|
[300] | 9 | |
---|
[335] | 10 | namespace xios |
---|
[300] | 11 | { |
---|
| 12 | using namespace std ; |
---|
| 13 | |
---|
| 14 | class CLog : public ostream |
---|
| 15 | { |
---|
| 16 | public : |
---|
[523] | 17 | CLog(const string& name_, std::streambuf* sBuff = cout.rdbuf()) |
---|
[1601] | 18 | : ostream(sBuff), level(0), name(name_), strBuf_(sBuff) |
---|
[490] | 19 | { |
---|
[1601] | 20 | omp_init_lock( &mutex ); |
---|
| 21 | for(int i=0; i<16; i++) |
---|
| 22 | strBuf_array[i] = sBuff; |
---|
[300] | 23 | } |
---|
[1601] | 24 | |
---|
| 25 | ~CLog() |
---|
| 26 | { |
---|
| 27 | omp_destroy_lock( &mutex ); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | CLog& operator()(int l); |
---|
[490] | 31 | void setLevel(int l) {level=l; } |
---|
[300] | 32 | int getLevel() {return level ;} |
---|
| 33 | bool isActive(void) { if (rdbuf()==NULL) return true ; else return false ;} |
---|
| 34 | bool isActive(int l) {if (l<=level) return true ; else return false ; } |
---|
| 35 | |
---|
[490] | 36 | public: |
---|
[523] | 37 | //! Write log into a file with its streambuf |
---|
[490] | 38 | void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); } |
---|
| 39 | |
---|
[523] | 40 | //! Write log into standard output |
---|
[490] | 41 | void write2StdOut() { changeStreamBuff(cout.rdbuf()); } |
---|
[523] | 42 | |
---|
| 43 | //! Write log into standard error output |
---|
| 44 | void write2StdErr() { changeStreamBuff(cerr.rdbuf()); } |
---|
| 45 | |
---|
[490] | 46 | private: |
---|
| 47 | /*! |
---|
| 48 | * \brief Change current streambuf (by default std::cout) to new one |
---|
| 49 | * This function associates a new streambuf to the current log object |
---|
| 50 | * \param [in] pointer to new streambuf |
---|
| 51 | */ |
---|
[1601] | 52 | void changeStreamBuff(std::streambuf* sBuff) |
---|
| 53 | { |
---|
| 54 | strBuf_ = sBuff; |
---|
| 55 | strBuf_array[omp_get_thread_num()] = sBuff; |
---|
| 56 | rdbuf(sBuff); |
---|
| 57 | } |
---|
[490] | 58 | |
---|
[300] | 59 | int level ; |
---|
[347] | 60 | string name ; |
---|
[490] | 61 | std::streambuf* strBuf_; |
---|
[1601] | 62 | std::streambuf* strBuf_array[16]; |
---|
| 63 | omp_lock_t mutex; |
---|
[300] | 64 | }; |
---|
| 65 | |
---|
| 66 | extern CLog info; |
---|
[347] | 67 | extern CLog report; |
---|
[523] | 68 | extern CLog error; |
---|
[1601] | 69 | |
---|
| 70 | extern std::filebuf* info_FB[16]; |
---|
[300] | 71 | } |
---|
| 72 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.