AOSharedServiceLibrary
logging_interface.h
1 /*
2 MIT License Block
3 
4 Copyright (c) 2016 Alex Barry
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #ifndef AOSSL_LOGGING_INCLUDE_LOGGING_INTERFACE_H_
26 #define AOSSL_LOGGING_INCLUDE_LOGGING_INTERFACE_H_
27 
28 #include <log4cpp/Category.hh>
29 #include <string>
30 #include <exception>
31 
32 const int AOSSL_LOG_DEBUG = 0;
33 const int AOSSL_LOG_INFO = 1;
34 const int AOSSL_LOG_ERROR = 2;
35 
37 struct LoggingException: public std::exception {
39  std::string int_msg;
40  const char * what_str;
41 
43  inline LoggingException(std::string msg) {
44  int_msg = "Error in Logging Driver: " + msg;
45  what_str = int_msg.c_str();
46  }
47 
48  LoggingException() {}
49  ~LoggingException() throw() {}
50 
52  const char * what() const throw() {
53  return what_str;
54  }
55 };
56 
59  public:
60  virtual ~LoggingCategoryInterface() {}
61 
62  // Exposures that log to the sepcified category
63 
65 
68  virtual void debug(std::string msg) = 0;
69 
71 
74  virtual void error(std::string msg) = 0;
75 
77 
80  virtual void info(std::string msg) = 0;
81 
83 
86  virtual void debug(const char * msg) = 0;
87 
89 
92  virtual void error(const char * msg) = 0;
93 
95 
98  virtual void info(const char * msg) = 0;
99 
101 
104  virtual void debug(int msg) = 0;
105 
107 
110  virtual void error(int msg) = 0;
111 
113 
116  virtual void info(int msg) = 0;
117 
119 
122  virtual void debug(float msg) = 0;
123 
125 
128  virtual void error(float msg) = 0;
129 
131  virtual void info(float msg) = 0;
132 
134 
137  virtual void debug(double msg) = 0;
138 
140 
143  virtual void error(double msg) = 0;
144 
146 
149  virtual void info(double msg) = 0;
150 };
151 
154  public:
155  virtual ~LoggingInterface() {}
156 
157  // Exposures that log to the root category
158 
160 
163  virtual void debug(std::string msg) = 0;
164 
166 
169  virtual void error(std::string msg) = 0;
170 
172 
175  virtual void info(std::string msg) = 0;
176 
178 
181  virtual void debug(const char * msg) = 0;
182 
184 
187  virtual void error(const char * msg) = 0;
188 
190 
193  virtual void info(const char * msg) = 0;
194 
196 
199  virtual void debug(int msg) = 0;
200 
202 
205  virtual void error(int msg) = 0;
206 
208 
211  virtual void info(int msg) = 0;
212 
214 
217  virtual void debug(float msg) = 0;
218 
220 
223  virtual void error(float msg) = 0;
224 
226 
229  virtual void info(float msg) = 0;
230 
232 
235  virtual void debug(double msg) = 0;
236 
238 
241  virtual void error(double msg) = 0;
242 
244 
247  virtual void info(double msg) = 0;
248 
252 
255  virtual LoggingCategoryInterface* get_category(std::string name) = 0;
256 };
257 
260 extern LoggingInterface *logging;
261 
262 #endif // AOSSL_LOGGING_INCLUDE_LOGGING_INTERFACE_H_
A Logging Category instantiated on a standard logging instance.
Definition: logging_interface.h:58
std::string int_msg
An error message passed on initialization.
Definition: logging_interface.h:39
LoggingException(std::string msg)
Create a Logging Exception, and store the given error message.
Definition: logging_interface.h:43
An overall logging interface, which can generate logging categories.
Definition: logging_interface.h:153
Logging Exception, used to store errors passed from the Logger.
Definition: logging_interface.h:37
const char * what() const
Show the error message in readable format.
Definition: logging_interface.h:52