μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
21namespace 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
#define UHAL_LOG_INSERT_WARNING
Definition: LogLevels.hpp:15
BaseLogLevel(std::ostream &aStr, fPtr aHeadFunction, fPtr aTailFunction)
Definition: LogLevels.hpp:46
std::ostream & stream()
Definition: LogLevels.hpp:70
std::ostream & mStr
Definition: LogLevels.hpp:76
void(* fPtr)(std::ostream &aStr)
Definition: LogLevels.hpp:44
Helper struct representing the Debug log level to allow us to specialize functions according to their...
Definition: LogLevels.hpp:159
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:128
BaseLogLevel< DebugLevel > Base
Definition: LogLevels.hpp:160
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:120
Helper struct representing the Error log level to allow us to specialize functions according to their...
Definition: LogLevels.hpp:100
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:56
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:48
BaseLogLevel< ErrorLevel > Base
Definition: LogLevels.hpp:101
Helper struct representing the Fatal log level to allow us to specialize functions according to their...
Definition: LogLevels.hpp:85
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:30
BaseLogLevel< FatalLevel > Base
Definition: LogLevels.hpp:86
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:38
Helper struct representing the Info log level to allow us to specialize functions according to their ...
Definition: LogLevels.hpp:145
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:110
BaseLogLevel< InfoLevel > Base
Definition: LogLevels.hpp:146
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:102
Helper struct representing the Notice log level to allow us to specialize functions according to thei...
Definition: LogLevels.hpp:130
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:84
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:92
BaseLogLevel< NoticeLevel > Base
Definition: LogLevels.hpp:132
Helper struct representing the Warning log level to allow us to specialize functions according to the...
Definition: LogLevels.hpp:116
static void colour_head(std::ostream &aStr)
Definition: LogLevels.cpp:66
BaseLogLevel< WarningLevel > Base
Definition: LogLevels.hpp:117
static void colour_tail(std::ostream &aStr)
Definition: LogLevels.cpp:74
DebugLevel Debug
Definition: LogLevels.cpp:133
_Integer< T, IntFmt<> > Integer(const T &aT)
Forward declare a function which creates an instance of the ultra-lightweight wrapper from an integer...
void insert(std::ostream &aStr, const U &aU)
Definition: LogLevels.hpp:25
ErrorLevel Error
Definition: LogLevels.cpp:61
FatalLevel Fatal
Definition: LogLevels.cpp:43
WarningLevel Warning
Definition: LogLevels.cpp:79
InfoLevel Info
Definition: LogLevels.cpp:115
NoticeLevel Notice
Definition: LogLevels.cpp:97