source: XIOS/trunk/src/log.hpp @ 490

Last change on this file since 490 was 490, checked in by mhnguyen, 7 years ago

Implementing print output in seperate files

+) Add an option to write information into standard output or into files,
each of which is created by a process
+) Add a new file for global data (constant, value macro, etc)
+) Do a minor change in how to generate doxygen

Test
+) On Curie, with two modes: only client (connected) and client-server
+) All tests passed, each client prints out its info in a seperate file

File size: 1.4 KB
Line 
1#ifndef __XIOS_LOG_HPP__
2#define __XIOS_LOG_HPP__
3
4#include <string>
5#include <iostream>
6#include <string>
7
8namespace xios
9{
10  using namespace std ;
11
12  class CLog : public ostream
13  {
14    public :
15    CLog(const string& name_) : ostream(cout.rdbuf()),level(0),name(name_), strBuf_(cout.rdbuf()) {}
16    CLog& operator()(int l)
17    {
18      if (l<=level)
19      {
20//        rdbuf(cout.rdbuf()) ;
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 info into a file with its streambuf
34    void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); }
35
36    //! Write info into standard output
37    void write2StdOut() { changeStreamBuff(cout.rdbuf()); }
38  private:
39    /*!
40     * \brief Change current streambuf (by default std::cout) to new one
41     * This function associates a new streambuf to the current log object
42     * \param [in] pointer to new streambuf
43    */
44    void changeStreamBuff(std::streambuf* sBuff) { strBuf_ = sBuff; rdbuf(sBuff); }
45
46    private :
47    int level ;
48    string name ;
49    std::streambuf* strBuf_;
50  };
51
52  extern CLog info;
53  extern CLog report;
54}
55#endif
Note: See TracBrowser for help on using the repository browser.