source: XIOS3/trunk/src/log_type.hpp @ 2408

Last change on this file since 2408 was 2341, checked in by ymipsl, 2 years ago

Implement new info log method.
Log must be now activated more selectivelly the by level using variable "log_type" key in the xios context.
ex :

<variable id="log_type" type="string">log_protocol</variable>

In code new object CLogType must be created and will be feed as argument to the info object :
ex :
static CLogType logProtocol("log_protocol") ;
...
info(logProtocol)<<"...."

info can be also tested to know if specific key to output log is active :
ex :

if (info.isActive(logProtocol)) ....

Previous method using integer level is still available.

YM

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1#ifndef __XIOS_LOG_TYPE_HPP__
2#define __XIOS_LOG_TYPE_HPP__
3
4#include <string>
5#include <iostream>
6#include <cstdint>
7#include <unordered_map>
8
9//#include "cxios.hpp"
10#include "string_tools.hpp"
11
12namespace xios
13{
14  class CSetLog ;
15
16  class CLogType
17  {
18    public: 
19
20    CLogType(void) {}
21    CLogType(const std::string& name) ;
22
23    static void bitSet(CLogType& log, int bitPos) { log.type_ |= (uint64_t)1 << bitPos ;}
24    static bool bitAnd(CLogType& log1, CLogType& log2) { return (log1.type_ & log2.type_) == log2.type_ ; }
25   
26    private:
27   
28    uint64_t type_=0 ;
29    int bitPos_=0 ;
30    static int globalBitPos_ ;
31   
32  } ;
33
34  class CSetLog
35  {
36    public:
37
38    CSetLog(void) ;
39    bool isSet(CLogType& log) { return CLogType::bitAnd(logType_, log) ; }
40
41    private:
42   
43    static int registerLog(const std::string& name, int bitPos) ;
44    static std::map<std::string, int>& getRegistredLog(void) ;
45   
46    CLogType logType_ ;
47    friend class CLogType ;
48  } ;
49
50
51
52}
53
54#endif
Note: See TracBrowser for help on using the repository browser.