source: XIOS/dev/branch_openmp/src/log.hpp @ 1348

Last change on this file since 1348 was 1342, checked in by yushan, 6 years ago

log files

  • 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
Line 
1#ifndef __XIOS_LOG_HPP__
2#define __XIOS_LOG_HPP__
3
4#include <string>
5#include <iostream>
6#include <string>
7#include <stdio.h>
8#include <omp.h>
9
10namespace xios
11{
12  using namespace std ;
13
14  class CLog : public ostream
15  {
16    public :
17    CLog(const string& name_, std::streambuf* sBuff = cout.rdbuf())
18      : ostream(sBuff), level(0), name(name_), strBuf_(sBuff) 
19    {
20      omp_init_lock( &mutex );
21      for(int i=0; i<16; i++)
22        strBuf_array[i] = sBuff;
23    }
24
25    ~CLog()
26    {
27      omp_destroy_lock( &mutex );
28    }
29
30    CLog& operator()(int l);
31    void setLevel(int l) {level=l; }
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
36  public:
37    //! Write log into a file with its streambuf
38    void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); }
39
40    //! Write log into standard output
41    void write2StdOut() { changeStreamBuff(cout.rdbuf()); }
42
43    //! Write log into standard error output
44    void write2StdErr() { changeStreamBuff(cerr.rdbuf()); }
45
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    */
52    void changeStreamBuff(std::streambuf* sBuff) 
53    { 
54      strBuf_ = sBuff; 
55      strBuf_array[omp_get_thread_num()] = sBuff;
56      rdbuf(sBuff);
57    }
58
59    int level ;
60    string name ;
61    std::streambuf* strBuf_;
62    std::streambuf* strBuf_array[16];
63    omp_lock_t mutex;
64  };
65
66  extern CLog info;
67  extern CLog report;
68  extern CLog error;
69
70  extern std::filebuf* info_FB[16];
71}
72#endif
Note: See TracBrowser for help on using the repository browser.