μHAL (v2.7.9)
Part of the IPbus software repository
LogLevels.hpp
Go to the documentation of this file.
1 
2 #ifndef _uhal_log_LogLevels_hpp_
3 #define _uhal_log_LogLevels_hpp_
4 
5 
6 #include <iostream>
7 #include <stdint.h>
8 
9 
10 // NOTE: the UHAL_LOG_INSERT_WARNING is defined to bridge between the compilers used on Linux and OSX.
11 // While on linux the 'warning' attribute is defined, it is not in OSX 10.9 clang.
12 // On the other hand clang's 'deprecated' is messageless in g++, while it supports messages in clang.
13 // To make the story short, UHAL_LOG_INSERT_WARNING uses the most appropriated attribute for the system in use.
14 #ifndef __clang__
15 #define UHAL_LOG_INSERT_WARNING warning
16 #else
17 #define UHAL_LOG_INSERT_WARNING deprecated
18 #endif
19 
20 
21 namespace uhal
22 {
23 
24  template< typename U>
25  void insert ( std::ostream& aStr , const U& aU )
26  {
27  aStr << aU;
28  }
29 
30  __attribute__ ( ( UHAL_LOG_INSERT_WARNING ( "Insertion of integer types can result in implicit casts. Consider using the Integer() formatter instead" ) ) )
31  void insert ( std::ostream& aStr , const uint32_t& aUint ) ;
32 
33  __attribute__ ( ( UHAL_LOG_INSERT_WARNING ( "Insertion of integer types can result in implicit casts. Consider using the Integer() formatter instead" ) ) )
34  void insert ( std::ostream& aStr , const int32_t& aInt );
35 
36  __attribute__ ( ( UHAL_LOG_INSERT_WARNING ( "Insertion of boolean types can result in implicit casts. Consider using the Boolean() formatter instead" ) ) )
37  void insert ( std::ostream& aStr , const bool& aBool );
38 
39 
40  template< typename T >
42  {
43  protected:
44  typedef void ( *fPtr ) ( std::ostream& aStr );
45 
46  BaseLogLevel ( std::ostream& aStr , fPtr aHeadFunction , fPtr aTailFunction ) :
47  mStr ( aStr ),
48  mHeadFunction ( aHeadFunction ),
49  mTailFunction ( aTailFunction )
50  {}
51 
52  public:
53  T& operator() ()
54  {
55  return static_cast<T&> ( *this );
56  }
57 
58  T& head()
59  {
60  mHeadFunction ( mStr );
61  return static_cast<T&> ( *this );
62  }
63 
64  T& tail()
65  {
66  mTailFunction ( mStr );
67  return static_cast<T&> ( *this );
68  }
69 
70  std::ostream& stream()
71  {
72  return mStr;
73  }
74 
75  private:
76  std::ostream& mStr;
79 
80  };
81 
82 
84  class FatalLevel : public BaseLogLevel< FatalLevel >
85  {
87 
88  public:
89  FatalLevel ( std::ostream& aStr = std::cout , Base::fPtr aHeadFunction = FatalLevel::colour_head, Base::fPtr aTailFunction = FatalLevel::colour_tail );
90 
91  static void colour_head ( std::ostream& aStr );
92  static void colour_tail ( std::ostream& aStr );
93  };
94 
95  extern FatalLevel Fatal;
96 
97 
99  class ErrorLevel : public BaseLogLevel< ErrorLevel >
100  {
102 
103  public:
104  ErrorLevel ( std::ostream& aStr = std::cout , Base::fPtr aHeadFunction = ErrorLevel::colour_head, Base::fPtr aTailFunction = ErrorLevel::colour_tail );
105 
106  static void colour_head ( std::ostream& aStr );
107  static void colour_tail ( std::ostream& aStr );
108  };
109 
110  extern ErrorLevel Error;
111 
112 
113 
115  class WarningLevel : public BaseLogLevel< WarningLevel >
116  {
118 
119  public:
120  WarningLevel ( std::ostream& aStr = std::cout , Base::fPtr aHeadFunction = WarningLevel::colour_head, Base::fPtr aTailFunction = WarningLevel::colour_tail );
121 
122  static void colour_head ( std::ostream& aStr );
123  static void colour_tail ( std::ostream& aStr );
124  };
125 
126  extern WarningLevel Warning;
127 
129  class NoticeLevel : public BaseLogLevel< NoticeLevel >
130  {
131 
133 
134  public:
135  NoticeLevel ( std::ostream& aStr = std::cout , Base::fPtr aHeadFunction = NoticeLevel::colour_head, Base::fPtr aTailFunction = NoticeLevel::colour_tail );
136 
137  static void colour_head ( std::ostream& aStr );
138  static void colour_tail ( std::ostream& aStr );
139  };
140 
141  extern NoticeLevel Notice;
142 
144  class InfoLevel : public BaseLogLevel< InfoLevel >
145  {
147 
148  public:
149  InfoLevel ( std::ostream& aStr = std::cout , Base::fPtr aHeadFunction = InfoLevel::colour_head, Base::fPtr aTailFunction = InfoLevel::colour_tail );
150 
151  static void colour_head ( std::ostream& aStr );
152  static void colour_tail ( std::ostream& aStr );
153  };
154 
155  extern InfoLevel Info;
156 
158  class DebugLevel : public BaseLogLevel< DebugLevel >
159  {
161 
162  public:
163  DebugLevel ( std::ostream& aStr = std::cout , Base::fPtr aHeadFunction = DebugLevel::colour_head, Base::fPtr aTailFunction = DebugLevel::colour_tail );
164 
165  static void colour_head ( std::ostream& aStr );
166  static void colour_tail ( std::ostream& aStr );
167  };
168 
169  extern DebugLevel Debug;
170 }
171 
172 
173 #endif
uhal::NoticeLevel
Helper struct representing the Notice log level to allow us to specialize functions according to thei...
Definition: LogLevels.hpp:130
uhal::WarningLevel::WarningLevel
WarningLevel(std::ostream &aStr=std::cout, Base::fPtr aHeadFunction=WarningLevel::colour_head, Base::fPtr aTailFunction=WarningLevel::colour_tail)
Definition: LogLevels.cpp:64
uhal::InfoLevel::InfoLevel
InfoLevel(std::ostream &aStr=std::cout, Base::fPtr aHeadFunction=InfoLevel::colour_head, Base::fPtr aTailFunction=InfoLevel::colour_tail)
Definition: LogLevels.cpp:100
uhal::ErrorLevel::colour_head
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:48
uhal::BaseLogLevel::BaseLogLevel
BaseLogLevel(std::ostream &aStr, fPtr aHeadFunction, fPtr aTailFunction)
Definition: LogLevels.hpp:46
uhal::ErrorLevel::Base
BaseLogLevel< ErrorLevel > Base
Definition: LogLevels.hpp:101
uhal::BaseLogLevel::tail
T & tail()
Definition: LogLevels.hpp:64
uhal::InfoLevel::colour_tail
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:110
uhal::BaseLogLevel::stream
std::ostream & stream()
Definition: LogLevels.hpp:70
uhal::InfoLevel::colour_head
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:102
uhal::BaseLogLevel::mTailFunction
fPtr mTailFunction
Definition: LogLevels.hpp:78
uhal::FatalLevel
Helper struct representing the Fatal log level to allow us to specialize functions according to their...
Definition: LogLevels.hpp:85
uhal::DebugLevel::colour_tail
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:128
uhal::insert
void insert(std::ostream &aStr, const U &aU)
Definition: LogLevels.hpp:25
uhal::WarningLevel::colour_tail
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:74
uhal::WarningLevel::Base
BaseLogLevel< WarningLevel > Base
Definition: LogLevels.hpp:117
uhal::FatalLevel::FatalLevel
FatalLevel(std::ostream &aStr=std::cout, Base::fPtr aHeadFunction=FatalLevel::colour_head, Base::fPtr aTailFunction=FatalLevel::colour_tail)
Definition: LogLevels.cpp:28
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::DebugLevel::colour_head
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:120
uhal::NoticeLevel::NoticeLevel
NoticeLevel(std::ostream &aStr=std::cout, Base::fPtr aHeadFunction=NoticeLevel::colour_head, Base::fPtr aTailFunction=NoticeLevel::colour_tail)
Definition: LogLevels.cpp:82
uhal::ErrorLevel::colour_tail
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:56
uhal::NoticeLevel::Base
BaseLogLevel< NoticeLevel > Base
Definition: LogLevels.hpp:132
uhal::InfoLevel::Base
BaseLogLevel< InfoLevel > Base
Definition: LogLevels.hpp:146
UHAL_LOG_INSERT_WARNING
#define UHAL_LOG_INSERT_WARNING
Definition: LogLevels.hpp:15
uhal::Info
InfoLevel Info
Definition: LogLevels.cpp:115
uhal::NoticeLevel::colour_tail
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:92
uhal::ErrorLevel::ErrorLevel
ErrorLevel(std::ostream &aStr=std::cout, Base::fPtr aHeadFunction=ErrorLevel::colour_head, Base::fPtr aTailFunction=ErrorLevel::colour_tail)
Definition: LogLevels.cpp:46
uhal::Integer
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
Definition: log_inserters.integer.hxx:43
uhal::BaseLogLevel::mStr
std::ostream & mStr
Definition: LogLevels.hpp:76
uhal::Warning
WarningLevel Warning
Definition: LogLevels.cpp:79
uhal::Error
ErrorLevel Error
Definition: LogLevels.cpp:61
uhal::FatalLevel::colour_tail
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:38
uhal::WarningLevel
Helper struct representing the Warning log level to allow us to specialize functions according to the...
Definition: LogLevels.hpp:116
uhal::InfoLevel
Helper struct representing the Info log level to allow us to specialize functions according to their ...
Definition: LogLevels.hpp:145
uhal::BaseLogLevel::head
T & head()
Definition: LogLevels.hpp:58
uhal::WarningLevel::colour_head
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:66
uhal::Debug
DebugLevel Debug
Definition: LogLevels.cpp:133
uhal::BaseLogLevel::mHeadFunction
fPtr mHeadFunction
Definition: LogLevels.hpp:77
uhal::FatalLevel::colour_head
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:30
uhal::DebugLevel::Base
BaseLogLevel< DebugLevel > Base
Definition: LogLevels.hpp:160
uhal::Notice
NoticeLevel Notice
Definition: LogLevels.cpp:97
uhal::BaseLogLevel
Definition: LogLevels.hpp:42
uhal::DebugLevel::DebugLevel
DebugLevel(std::ostream &aStr=std::cout, Base::fPtr aHeadFunction=DebugLevel::colour_head, Base::fPtr aTailFunction=DebugLevel::colour_tail)
Definition: LogLevels.cpp:118
uhal::DebugLevel
Helper struct representing the Debug log level to allow us to specialize functions according to their...
Definition: LogLevels.hpp:159
uhal::Fatal
FatalLevel Fatal
Definition: LogLevels.cpp:43
uhal::NoticeLevel::colour_head
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:84
uhal::FatalLevel::Base
BaseLogLevel< FatalLevel > Base
Definition: LogLevels.hpp:86
uhal::ErrorLevel
Helper struct representing the Error log level to allow us to specialize functions according to their...
Definition: LogLevels.hpp:100
uhal::BaseLogLevel< FatalLevel >::fPtr
void(* fPtr)(std::ostream &aStr)
Definition: LogLevels.hpp:44