LArOpenCV  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
larcaffe_logger.h
Go to the documentation of this file.
1 
14 #ifndef __LARCAFFELOGGER_H__
15 #define __LARCAFFELOGGER_H__
16 
17 #include <cstdio>
18 #include <iostream>
19 #include <map>
20 //#include "LArCaffe/LArCaffeTypes.h"
21 #include "LArCaffeTypes.h"
22 
23 namespace larcaffe {
24 
31  class logger{
32 
33  public:
34 
36  logger(const std::string& name="no_name")
37  : _ostrm(&std::cout)
38  , _name(name)
39  {}
40 
42  virtual ~logger(){};
43 
44  private:
45 
47  std::ostream *_ostrm;
48 
51 
53  std::string _name;
54 
56  static std::map<std::string,larcaffe::logger> *_logger_m;
57 
58  public:
59 
61  const std::string& name() const { return _name; }
62 
64  void set(const msg::Level_t level) { _level = level; }
65 
67  msg::Level_t level() const { return _level; }
68 
70  inline bool operator<(const logger& rhs) const
71  {
72  if(_name < rhs.name()) return true;
73  if(_name > rhs.name()) return false;
74  return false;
75  }
76 
78  static logger& get(const std::string name)
79  {
80  if(!_logger_m) _logger_m = new std::map<std::string,larcaffe::logger>();
81  auto iter = _logger_m->find(name);
82  if(iter == _logger_m->end()) {
83  iter = _logger_m->emplace(name,logger(name)).first;
84  iter->second.set(msg::kNORMAL);
85  }
86  return iter->second;
87  };
88  //
89  // Verbosity level checker
90  //
91  inline bool debug () const { return _level <= msg::kDEBUG; }
92  inline bool info () const { return _level <= msg::kINFO; }
93  inline bool normal () const { return _level <= msg::kNORMAL; }
94  inline bool warning () const { return _level <= msg::kWARNING; }
95  inline bool error () const { return _level <= msg::kERROR; }
97  std::ostream& send(const msg::Level_t) const;
99  std::ostream& send(const msg::Level_t level,
100  const std::string& function ) const;
102  std::ostream& send(const msg::Level_t level,
103  const std::string& function,
104  const unsigned int line_num ) const;
106  std::ostream& send(const msg::Level_t level,
107  const std::string& function,
108  const unsigned int line_num,
109  const std::string& file_name) const;
110 
111  };
112 }
113 //
114 // Compiler macro for saving us from text typing
115 //
116 #define LARCAFFE_DEBUG(obj) obj.send(::larcaffe::msg::kDEBUG,__FUNCTION__,__LINE__,__FILE__)
117 #define LARCAFFE_INFO(obj) obj.send(::larcaffe::msg::kINFO,__FUNCTION__,__LINE__)
118 #define LARCAFFE_NORMAL(obj) obj.send(::larcaffe::msg::kNORMAL,__FUNCTION__)
119 #define LARCAFFE_WARNING(obj) obj.send(::larcaffe::msg::kWARNING,__FUNCTION__)
120 #define LARCAFFE_ERROR(obj) obj.send(::larcaffe::msg::kERROR,__FUNCTION__,__LINE__)
121 #define LARCAFFE_CRITICAL(obj) obj.send(::larcaffe::msg::kCRITICAL,__FUNCTION__,__LINE__,__FILE__)
122  // end of doxygen group logger
124 #endif