All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpT0FinderLogger.h
Go to the documentation of this file.
1 /**
2  * \file OpT0FinderLogger.h
3  *
4  * \ingroup Base
5  *
6  * \brief logger utility class definition header file.
7  *
8  * @author Kazu - Nevis 2015
9  */
10 
11 /** \addtogroup Base
12 
13  @{*/
14 #ifndef __OPT0FINDERLOGGER_H__
15 #define __OPT0FINDERLOGGER_H__
16 
17 #include <cstdio>
18 #include <iostream>
19 #include <map>
20 #include "OpT0FinderTypes.h"
21 
22 namespace flashmatch {
23 
24  /**
25  \class logger
26  \brief Utility class used to show formatted message on the screen.
27  A logger class for flashmatch. Simply shows a formatted colored message on a screen. \n
28  A static getter method is provided to create a sharable logger instance (see OpT0FinderBase for useage). \n
29  */
30  class logger{
31 
32  public:
33 
34  /// Default constructor
35  logger(const std::string& name="no_name")
36  : _ostrm(&std::cout)
37  , _name(name)
38  {}
39 
40  /// Default destructor
41  virtual ~logger(){};
42 
43  private:
44 
45  /// ostream
46  std::ostream *_ostrm;
47 
48  /// Level
50 
51  /// Name
52  std::string _name;
53 
54  /// Set of loggers
55  static std::map<std::string,flashmatch::logger> *_logger_m;
56 
57  /// Default logger level
59 
60  public:
61 
62  /// Logger's name
63  const std::string& name() const { return _name; }
64 
65  /// Verbosity level setter
66  void set(const msg::Level_t level) { _level = level; }
67 
68  /// Verbosity level getter
69  msg::Level_t level() const { return _level; }
70 
71  /// Comparison operator for static collection of loggers
72  inline bool operator<(const logger& rhs) const
73  {
74  if(_name < rhs.name()) return true;
75  if(_name > rhs.name()) return false;
76  return false;
77  }
78 
79  /// Getter of a message instance
80  static logger& get(const std::string name)
81  {
82  if(!_logger_m) _logger_m = new std::map<std::string,flashmatch::logger>();
83  auto iter = _logger_m->find(name);
84  if(iter == _logger_m->end()) {
85  iter = _logger_m->emplace(name,logger(name)).first;
86  iter->second.set(msg::kNORMAL);
87  }
88  return iter->second;
89  };
90 
91  /// Default logger level getter
93  /// Default logger level setter (only affect future loggers)
94  static void default_level(msg::Level_t l) { _level_default = l; }
95  /// Force all loggers to change level
96  static void force_level(msg::Level_t l)
97  {
98  default_level(l);
99  for(auto& name_logger : *_logger_m) name_logger.second.set(l);
100  }
101 
102  //
103  // Verbosity level checker
104  //
105  inline bool debug () const { return _level <= msg::kDEBUG; }
106  inline bool info () const { return _level <= msg::kINFO; }
107  inline bool normal () const { return _level <= msg::kNORMAL; }
108  inline bool warning () const { return _level <= msg::kWARNING; }
109  inline bool error () const { return _level <= msg::kERROR; }
110  /// Formatted message (simplest)
111  std::ostream& send(const msg::Level_t) const;
112  /// Formatted message (function name included)
113  std::ostream& send(const msg::Level_t level,
114  const std::string& function ) const;
115  /// Formatted message (function name + line number)
116  std::ostream& send(const msg::Level_t level,
117  const std::string& function,
118  const unsigned int line_num ) const;
119  /// Formatted message (function name + line number + file name)
120  std::ostream& send(const msg::Level_t level,
121  const std::string& function,
122  const unsigned int line_num,
123  const std::string& file_name) const;
124 
125  };
126 }
127 //
128 // Compiler macro for saving us from text typing
129 //
130 /// Compiler macro for DEBUG message
131 #define FLASH_DEBUG() if( logger().debug () ) logger().send(::flashmatch::msg::kDEBUG, __FUNCTION__, __LINE__, __FILE__)
132 /// Compiler macro for INFO message
133 #define FLASH_INFO() if( logger().info () ) logger().send(::flashmatch::msg::kINFO, __FUNCTION__, __LINE__ )
134 /// Compiler macro for NORMAL message
135 #define FLASH_NORMAL() if( logger().normal () ) logger().send(::flashmatch::msg::kNORMAL, __FUNCTION__ )
136 /// Compiler macro for WARNING message
137 #define FLASH_WARNING() if( logger().warning () ) logger().send(::flashmatch::msg::kWARNING, __FUNCTION__ )
138 /// Compiler macro for ERROR message
139 #define FLASH_ERROR() if( logger().error () ) logger().send(::flashmatch::msg::kERROR, __FUNCTION__, __LINE__ )
140 /// Compiler macro for CRITICAL message
141 #define FLASH_CRITICAL() logger().send(::flashmatch::msg::kCRITICAL, __FUNCTION__, __LINE__, __FILE__)
142 
143 /** @} */ // end of doxygen group logger
144 #endif
static msg::Level_t default_level()
Default logger level getter.
std::string _name
Name.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
msg::Level_t level() const
Verbosity level getter.
static void default_level(msg::Level_t l)
Default logger level setter (only affect future loggers)
logger(const std::string &name="no_name")
Default constructor.
std::ostream * _ostrm
ostream
static void force_level(msg::Level_t l)
Force all loggers to change level.
virtual ~logger()
Default destructor.
std::ostream & send(const msg::Level_t) const
Formatted message (simplest)
bool warning() const
msg::Level_t _level
Level.
Utility class used to show formatted message on the screen. A logger class for flashmatch. Simply shows a formatted colored message on a screen. A static getter method is provided to create a sharable logger instance (see OpT0FinderBase for useage). .
const std::string & name() const
Logger&#39;s name.
bool normal() const
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production file_name
static std::map< std::string, flashmatch::logger > * _logger_m
Set of loggers.
Level_t
Verbosity message level.
bool operator<(const logger &rhs) const
Comparison operator for static collection of loggers.
static msg::Level_t _level_default
Default logger level.
void set(const msg::Level_t level)
Verbosity level setter.
BEGIN_PROLOG could also be cout