API
 
Loading...
Searching...
No Matches
software_log.hpp
Go to the documentation of this file.
1/** \file software_log.hpp
2 * \brief The MagAO-X logger software_log log type.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_types_files
6 *
7 * History:
8 * - 2018-08-18 created by JRM
9 */
10#ifndef logger_types_software_log_hpp
11#define logger_types_software_log_hpp
12
13#include <source_location>
14
16#include "flatbuffer_log.hpp"
17
18namespace MagAOX
19{
20namespace logger
21{
22
23/// Base class for software logs
24/** Such logs are used to log software status, warnings, and errors. Does not have defaultLevel, so this can not be used
25 * as a log type in logger.
26 *
27 * \includedoc sw_logs.dox.inc
28 *
29 *
30 * \ingroup logger_types__basic
31 */
33{
34 /// The event code
36
37 /// The type of the message
38 struct messageT : public fbMessage
39 {
40 /// C'tor with full specification.
41 messageT( const char *file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
42 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
43 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be
44 ///< passed here, so strerror can be used later.
45 const int32_t otherCode, ///< [in] Some other error code, such as a return value or library code.
46 const char *explanation ///< [in] explanatory text about the software event
47 )
48 {
49 auto _file = builder.CreateString( file );
50 auto _expl = builder.CreateString( explanation );
51
52 auto gs = CreateSoftware_log_fb( builder, _file, line, errnoCode, otherCode, _expl );
53 builder.Finish( gs );
54 }
55
56 /// C'tor with full specification, overloaded for a std::string in explanation.
57 /** \overload
58 */
59 messageT( const char *file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
60 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
61 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be
62 ///< passed here, so strerror can be used later.
63 const int32_t otherCode, ///< [in] Some other error code, such as a return value or library code.
64 const std::string &explanation ///< [in] explanatory text about the software event
65 )
66 {
67 auto _file = builder.CreateString( file );
68 auto _expl = builder.CreateString( explanation );
69
70 auto gs = CreateSoftware_log_fb( builder, _file, line, errnoCode, otherCode, _expl );
71 builder.Finish( gs );
72 }
73
74 /// C'tor for errno only -- code explanation can be looked up later.
75 messageT( const char *file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
76 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
77 const int32_t errnoCode ///< [in] The errno code at the time of the log entry. Only errno should be
78 ///< passed here, so strerror can be used later.
79 )
80 {
81 auto _file = builder.CreateString( file );
82
83 auto gs = CreateSoftware_log_fb( builder, _file, line, errnoCode, 0, 0 );
84 builder.Finish( gs );
85 }
86
87 /// C'tor for errno with additional explanation.
88 messageT( const char *file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
89 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
90 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be
91 ///< passed here, so strerror can be used later.
92 const char *explanation ///< [in] explanatory text about the software event
93 )
94 {
95 auto _file = builder.CreateString( file );
96 auto _expl = builder.CreateString( explanation );
97
98 auto gs = CreateSoftware_log_fb( builder, _file, line, errnoCode, 0, _expl );
99 builder.Finish( gs );
100 }
101
102 /// C'tor for errno with additional explanation, std::string overload.
103 messageT( const char *file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
104 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
105 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be
106 ///< passed here, so strerror can be used later.
107 const std::string &explanation ///< [in] explanatory text about the software event
108 )
109 {
110 auto _file = builder.CreateString( file );
111 auto _expl = builder.CreateString( explanation );
112
113 auto gs = CreateSoftware_log_fb( builder, _file, line, errnoCode, 0, _expl );
114 builder.Finish( gs );
115 }
116
117 /// C'tor with no codes, just the explanation.
118 messageT( const char *file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
119 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
120 const std::string &explanation ///< [in] explanatory text about the software event
121 )
122 {
123 auto _file = builder.CreateString( file );
124 auto _expl = builder.CreateString( explanation );
125
126 auto gs = CreateSoftware_log_fb( builder, _file, line, 0, 0, _expl );
127 builder.Finish( gs );
128 }
129
130 /// C'tor for a trace log, only the file and line.
131 messageT( const char *file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
132 const uint32_t line ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
133 )
134 {
135 auto _file = builder.CreateString( file );
136
137 auto gs = CreateSoftware_log_fb( builder, _file, line, 0, 0, 0 );
138 builder.Finish( gs );
139 }
140
141 // constructors using source location
142
143 messageT( const int32_t errnoCode, /**< [in] The errno code at the time of the log entry. Only
144 errno should be passed here, so strerror can be used later.*/
145 const int32_t otherCode, /**< [in] Some other error code, such as a return value or
146 library code. */
147 const char *explanation, /**< [in] explanatory text about the software event*/
148 const std::source_location &loc /**< [in] [opt] source location */
149 = std::source_location::current() )
150 {
151 auto _file = builder.CreateString( loc.file_name() );
152 auto _expl = builder.CreateString( explanation );
153
154 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, otherCode, _expl );
155 builder.Finish( gs );
156 }
157
158 messageT( const int32_t errnoCode, /**< [in] The errno code at the time of the log entry. Only
159 errno should be passed here, so strerror can be used later.*/
160 const int32_t otherCode, /**< [in] Some other error code, such as a return value or
161 library code. */
162 const std::string &explanation, /**< [in] explanatory text about the software event*/
163 const std::source_location &loc /**< [in] [opt] source location */
164 = std::source_location::current() )
165 {
166 auto _file = builder.CreateString( loc.file_name() );
167 auto _expl = builder.CreateString( explanation );
168
169 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, otherCode, _expl );
170 builder.Finish( gs );
171 }
172
173 /// C'tor for errno only -- code explanation can be looked up later.
174 messageT( const int32_t errnoCode, /**< [in] The errno code at the time of the log entry. Only errno should be
175 passed here, so strerror can be used later.*/
176 const std::source_location &loc /**< [in] [opt] source location */
177 = std::source_location::current() )
178 {
179 auto _file = builder.CreateString( loc.file_name() );
180
181 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, 0, 0 );
182 builder.Finish( gs );
183 }
184
185 /// C'tor for errno with additional explanation.
186 messageT( const int32_t errnoCode, /**< [in] The errno code at the time of the log entry. Only errno should be
187 passed here, so strerror can be used later.*/
188 const char *explanation, ///< [in] explanatory text about the software event
189 const std::source_location &loc /**< [in] [opt] source location */
190 = std::source_location::current() )
191 {
192 auto _file = builder.CreateString( loc.file_name() );
193 auto _expl = builder.CreateString( explanation );
194
195 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, 0, _expl );
196 builder.Finish( gs );
197 }
198
199 /// C'tor for errno with additional explanation.
200 messageT( const int32_t errnoCode, /**< [in] The errno code at the time of the log entry. Only errno should be
201 passed here, so strerror can be used later.*/
202 const std::string &explanation, ///< [in] explanatory text about the software event
203 const std::source_location &loc /**< [in] [opt] source location */
204 = std::source_location::current() )
205 {
206 auto _file = builder.CreateString( loc.file_name() );
207 auto _expl = builder.CreateString( explanation );
208
209 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, 0, _expl );
210 builder.Finish( gs );
211 }
212
213 /// C'tor with no codes, just the explanation.
214 messageT( const char *explanation, /**< [in] explanatory text about the software event */
215 const std::source_location &loc /**< [in] [opt] source location */
216 = std::source_location::current() )
217 {
218 auto _file = builder.CreateString( loc.file_name() );
219 auto _expl = builder.CreateString( explanation );
220
221 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), 0, 0, _expl );
222
223 builder.Finish( gs );
224 }
225
226 /// C'tor with no codes, just the explanation.
227 messageT( const std::string &explanation, /**< [in] explanatory text about the software event */
228 const std::source_location &loc /**< [in] [opt] source location */
229 = std::source_location::current() )
230 {
231 auto _file = builder.CreateString( loc.file_name() );
232 auto _expl = builder.CreateString( explanation );
233
234 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), 0, 0, _expl );
235
236 builder.Finish( gs );
237 }
238
239 /// C'tor for a trace log, only the file and line.
240 messageT( const std::source_location &loc /**< [in] [opt] source location */
241 = std::source_location::current() )
242 {
243 auto _file = builder.CreateString( loc.file_name() );
244
245 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), 0, 0, 0 );
246 builder.Finish( gs );
247 }
248 };
249
250 static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
251 flatlogs::msgLenT len ///< [in] length of msgBuffer.
252 )
253 {
254 auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
255 static_cast<size_t>( len ) );
256 return VerifySoftware_log_fbBuffer( verifier );
257 }
258
259 /// Get the message formatted for human consumption.
260 static std::string msgString( void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
261 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
262 )
263 {
264
265 static_cast<void>( len );
266
267 auto rgs = GetSoftware_log_fb( msgBuffer );
268
269 std::string ret = "SW FILE: ";
270 if( rgs->file() != nullptr )
271 {
272 ret += rgs->file()->c_str();
273 }
274 else
275 {
276 ret += "????";
277 }
278
279 ret += std::format( " LINE: {}", rgs->line() );
280
281 if( rgs->errnoCode() )
282 {
283 ret += std::format( " ERRNO: {} [{}]", rgs->errnoCode(), rgs->errnoCode() );
284 }
285 if( rgs->otherCode() )
286 {
287 ret += std::format( " CODE: {}", rgs->otherCode() );
288 if( rgs->explanation() )
289 {
290 ret += std::format( " [{}]", rgs->explanation()->c_str() );
291 }
292 }
293 else if( rgs->explanation() )
294 {
295 ret += " >";
296 ret += rgs->explanation()->c_str();
297 }
298 return ret;
299 }
300
301 /// Get an empty logMetaDetail because meta data doesn't make sense for this log
302 /**
303 * \returns an empty logMetaDetail
304 */
305 static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
306 {
307 static_cast<void>( member );
308
309 std::cerr << "meta data doesn't make sense for software_log.\n";
310 return logMetaDetail();
311 }
312};
313
314/// Software EMERGENCY log entry
315/** This should only be used for a system-wide emergency requiring operator or automatic shutdown. Not for a process
316 * specific problem.
317 * \includedoc sw_logs.dox.inc
318 * \ingroup logger_types
319 */
321{
322 /// The default level
324};
325
326/// Software ALERT log entry
327/** This should only be used for a system-wide emergency requiring operator or automatic action. Not for a process
328 * specific problem.
329 * \includedoc sw_logs.dox.inc
330 * \ingroup logger_types
331 */
333{
334 /// The default level
336};
337
338/// Software CRITICAL log entry
339/** This should only be used if the process is going to shutdown.
340 * \includedoc sw_logs.dox.inc
341 * \ingroup logger_types
342 */
344{
345 /// The default level
347};
348
349/// Software ERR log entry
350/** Used to record and error that the process will attempt to recover from.
351 * \includedoc sw_logs.dox.inc
352 * \ingroup logger_types
353 */
355{
356 /// The default level
358};
359
360/// Software WARN log entry
361/** Used to record an abnormal condition.
362 * \includedoc sw_logs.dox.inc
363 * \ingroup logger_types
364 */
366{
367 /// The default level
369};
370
371/// Software NOTICE log entry
372/** Used to record a normal but signficant event or condition.
373 * \includedoc sw_logs.dox.inc
374 * \ingroup logger_types
375 */
377{
378 /// The default level
380};
381
382/// Software INFO log entry
383/** \includedoc sw_logs.dox.inc
384 * Used to record a normal event or condition. This is the lowest priority used in normal operations.
385 * \ingroup logger_types
386 */
388{
389 /// The default level
391};
392
393/// Software DEBUG log entry
394/** \includedoc sw_logs.dox.inc
395 * \ingroup logger_types
396 */
398{
399 /// The default level
401};
402
403/// Software DEBUG2 log entry
404/** \includedoc sw_logs.dox.inc
405 * \ingroup logger_types
406 */
408{
409 /// The default level
411};
412
413} // namespace logger
414} // namespace MagAOX
415
416#endif // logger_types_software_log_hpp
The MagAO-X logger flatbuffer log base type.
uint16_t eventCodeT
The type of an event code (16-bit unsigned int).
Definition logDefs.hpp:40
msgLen2T msgLenT
The type used to refer to the message length, regardless of length.
Definition logDefs.hpp:69
int8_t logPrioT
The type of the log priority code.
Definition logDefs.hpp:21
static void * messageBuffer(bufferPtrT &logBuffer)
Get the message buffer address.
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
static constexpr flatlogs::eventCodeT SOFTWARE_LOG
Definition logCodes.hpp:14
inline ::flatbuffers::Offset< Software_log_fb > CreateSoftware_log_fb(::flatbuffers::FlatBufferBuilder &_fbb, ::flatbuffers::Offset<::flatbuffers::String > file=0, uint32_t line=0, int32_t errnoCode=0, int32_t otherCode=0, ::flatbuffers::Offset<::flatbuffers::String > explanation=0)
const MagAOX::logger::Software_log_fb * GetSoftware_log_fb(const void *buf)
bool VerifySoftware_log_fbBuffer(::flatbuffers::Verifier &verifier)
Definition dm.hpp:19
static constexpr logPrioT LOG_NOTICE
A normal but significant condition.
static constexpr logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
static constexpr logPrioT LOG_CRITICAL
The process can not continue and will shut down (fatal)
static constexpr logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
static constexpr logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
static constexpr logPrioT LOG_EMERGENCY
Normal operations of the entire system should be shut down immediately.
static constexpr logPrioT LOG_DEBUG
Used for debugging.
static constexpr logPrioT LOG_DEBUG2
Used for debugging, providing a 2nd level.
static constexpr logPrioT LOG_ALERT
This should only be used if some action is required by operators to keep the system safe.
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
Software ALERT log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software CRITICAL log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software DEBUG2 log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software DEBUG log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software EMERGENCY log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software ERR log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software INFO log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
messageT(const char *file, const uint32_t line, const int32_t errnoCode, const int32_t otherCode, const std::string &explanation)
C'tor with full specification, overloaded for a std::string in explanation.
messageT(const char *file, const uint32_t line, const std::string &explanation)
C'tor with no codes, just the explanation.
messageT(const char *file, const uint32_t line, const int32_t errnoCode)
C'tor for errno only – code explanation can be looked up later.
messageT(const char *file, const uint32_t line, const int32_t errnoCode, const std::string &explanation)
C'tor for errno with additional explanation, std::string overload.
messageT(const std::string &explanation, const std::source_location &loc=std::source_location::current())
C'tor with no codes, just the explanation.
messageT(const char *file, const uint32_t line)
C'tor for a trace log, only the file and line.
messageT(const std::source_location &loc=std::source_location::current())
C'tor for a trace log, only the file and line.
messageT(const int32_t errnoCode, const int32_t otherCode, const char *explanation, const std::source_location &loc=std::source_location::current())
messageT(const char *file, const uint32_t line, const int32_t errnoCode, const int32_t otherCode, const char *explanation)
C'tor with full specification.
messageT(const int32_t errnoCode, const char *explanation, const std::source_location &loc=std::source_location::current())
C'tor for errno with additional explanation.
messageT(const char *explanation, const std::source_location &loc=std::source_location::current())
C'tor with no codes, just the explanation.
messageT(const int32_t errnoCode, const int32_t otherCode, const std::string &explanation, const std::source_location &loc=std::source_location::current())
messageT(const int32_t errnoCode, const std::source_location &loc=std::source_location::current())
C'tor for errno only – code explanation can be looked up later.
messageT(const char *file, const uint32_t line, const int32_t errnoCode, const char *explanation)
C'tor for errno with additional explanation.
messageT(const int32_t errnoCode, const std::string &explanation, const std::source_location &loc=std::source_location::current())
C'tor for errno with additional explanation.
Base class for software logs.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static const flatlogs::eventCodeT eventCode
The event code.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatted for human consumption.
static logMetaDetail getAccessor(const std::string &member)
Get an empty logMetaDetail because meta data doesn't make sense for this log.
Software NOTICE log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software WARN log entry.
static const flatlogs::logPrioT defaultLevel
The default level.