source: XIOS/dev/dev_ym/XIOS_COUPLING/src/log_type.cpp @ 2341

Last change on this file since 2341 was 2341, checked in by ymipsl, 23 months 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:eol-style set to native
  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#include "log_type.hpp"
2#include "cxios.hpp"
3
4namespace xios
5{
6  using namespace std ;
7 
8  int CLogType::globalBitPos_ = 0 ;
9
10  CLogType::CLogType(const std::string& name)
11  {
12    bitPos_ = CSetLog::registerLog(name, globalBitPos_) ;
13    if (bitPos_==-1) 
14    { 
15       bitPos_ = globalBitPos_ ;
16       globalBitPos_++ ;
17       if (globalBitPos_>63) ERROR("CLogType::CLogType(const std::string& name)",<<"max registred Log must be <64, need to modify CLogTyPe class algorithm") ;
18    }
19    type_ = (uint64_t)1 << bitPos_ ;
20  }
21
22  CSetLog::CSetLog(void)
23  {
24    std::string strIds = CXios::getin<std::string>("log_type","") ;
25    std::vector<std::string> names = splitRegex(strIds,"\\s* \\s*") ;
26   
27    auto& registredLog=getRegistredLog() ;
28
29    for(auto& name : names) 
30    {
31      auto it = registredLog.find(name) ;
32      if (it != registredLog.end()) CLogType::bitSet(logType_, it->second) ;
33    }
34  }
35
36  int CSetLog::registerLog(const std::string& name, int bitPos) 
37  { 
38    auto& registredLog = getRegistredLog() ;
39    auto it = registredLog.find(name) ;
40    if (it == registredLog.end()) 
41    {
42      registredLog.insert(pair<string, int>(name, bitPos)) ;
43      return -1 ;
44    }
45    else return it->second ;
46  }
47 
48  std::map<std::string, int>& CSetLog::getRegistredLog(void)
49  {
50    static std::map<std::string, int> registredLog ;
51    return registredLog ;
52  }
53
54}
Note: See TracBrowser for help on using the repository browser.