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 errno should be
144 passed here, so strerror can be used later.*/
145 const int32_t otherCode, ///< [in] Some other error code, such as a return value or library code.
146 const char *explanation, ///< [in] explanatory text about the software event
147 const std::source_location &loc /**< [in] [opt] source location */
148 = std::source_location::current()
149 )
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 /// C'tor for errno only -- code explanation can be looked up later.
159 messageT( const int32_t errnoCode, /**< [in] The errno code at the time of the log entry. Only errno should be
160 passed here, so strerror can be used later.*/
161 const std::source_location &loc /**< [in] [opt] source location */
162 = std::source_location::current() )
163 {
164 auto _file = builder.CreateString( loc.file_name() );
165
166 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, 0, 0 );
167 builder.Finish( gs );
168 }
169
170 /// C'tor for errno with additional explanation.
171 messageT( const int32_t errnoCode, /**< [in] The errno code at the time of the log entry. Only errno should be
172 passed here, so strerror can be used later.*/
173 const char *explanation, ///< [in] explanatory text about the software event
174 const std::source_location &loc /**< [in] [opt] source location */
175 = std::source_location::current()
176 )
177 {
178 auto _file = builder.CreateString( loc.file_name() );
179 auto _expl = builder.CreateString( explanation );
180
181 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, 0, _expl );
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 std::string & 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 {
193 auto _file = builder.CreateString( loc.file_name() );
194 auto _expl = builder.CreateString( explanation );
195
196 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), errnoCode, 0, _expl );
197 builder.Finish( gs );
198 }
199
200 /// C'tor with no codes, just the explanation.
201 messageT( const std::string &explanation, /**< [in] explanatory text about the software event */
202 const std::source_location &loc /**< [in] [opt] source location */
203 = std::source_location::current() )
204 {
205 auto _file = builder.CreateString( loc.file_name() );
206 auto _expl = builder.CreateString( explanation );
207
208 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), 0, 0, _expl );
209
210 builder.Finish( gs );
211 }
212
213 /// C'tor for a trace log, only the file and line.
214 messageT( const std::source_location &loc /**< [in] [opt] source location */
215 = std::source_location::current() )
216 {
217 auto _file = builder.CreateString( loc.file_name() );
218
219 auto gs = CreateSoftware_log_fb( builder, _file, loc.line(), 0, 0, 0 );
220 builder.Finish( gs );
221 }
222 };
223
224 static bool verify( flatlogs::bufferPtrT &logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
225 flatlogs::msgLenT len ///< [in] length of msgBuffer.
226 )
227 {
228 auto verifier = flatbuffers::Verifier( static_cast<uint8_t *>( flatlogs::logHeader::messageBuffer( logBuff ) ),
229 static_cast<size_t>( len ) );
230 return VerifySoftware_log_fbBuffer( verifier );
231 }
232
233 /// Get the message formatted for human consumption.
234 static std::string msgString( void *msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
235 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
236 )
237 {
238
239 static_cast<void>( len );
240
241 auto rgs = GetSoftware_log_fb( msgBuffer );
242
243 std::string ret = "SW FILE: ";
244 if( rgs->file() != nullptr )
245 {
246 ret += rgs->file()->c_str();
247 }
248 else
249 {
250 ret += "????";
251 }
252
253 ret += std::format( " LINE: {}", rgs->line() );
254
255 if( rgs->errnoCode() )
256 {
257 ret += std::format( " ERRNO: {} [{}]", rgs->errnoCode(), rgs->errnoCode() );
258 }
259 if( rgs->otherCode() )
260 {
261 ret += std::format( " CODE: {}", rgs->otherCode() );
262 if( rgs->explanation() )
263 {
264 ret += std::format( " [{}]", rgs->explanation()->c_str() );
265 }
266 }
267 else if( rgs->explanation() )
268 {
269 ret += " >";
270 ret += rgs->explanation()->c_str();
271 }
272 return ret;
273 }
274
275 /// Get an empty logMetaDetail because meta data doesn't make sense for this log
276 /**
277 * \returns an empty logMetaDetail
278 */
279 static logMetaDetail getAccessor( const std::string &member /**< [in] the name of the member */ )
280 {
281 static_cast<void>( member );
282
283 std::cerr << "meta data doesn't make sense for software_log.\n";
284 return logMetaDetail();
285 }
286};
287
288/// Software EMERGENCY log entry
289/** This should only be used for a system-wide emergency requiring operator or automatic shutdown. Not for a process
290 * specific problem.
291 * \includedoc sw_logs.dox.inc
292 * \ingroup logger_types
293 */
295{
296 /// The default level
298};
299
300/// Software ALERT log entry
301/** This should only be used for a system-wide emergency requiring operator or automatic action. Not for a process
302 * specific problem.
303 * \includedoc sw_logs.dox.inc
304 * \ingroup logger_types
305 */
307{
308 /// The default level
310};
311
312/// Software CRITICAL log entry
313/** This should only be used if the process is going to shutdown.
314 * \includedoc sw_logs.dox.inc
315 * \ingroup logger_types
316 */
318{
319 /// The default level
321};
322
323/// Software ERR log entry
324/** Used to record and error that the process will attempt to recover from.
325 * \includedoc sw_logs.dox.inc
326 * \ingroup logger_types
327 */
329{
330 /// The default level
332};
333
334/// Software WARN log entry
335/** Used to record an abnormal condition.
336 * \includedoc sw_logs.dox.inc
337 * \ingroup logger_types
338 */
340{
341 /// The default level
343};
344
345/// Software NOTICE log entry
346/** Used to record a normal but signficant event or condition.
347 * \includedoc sw_logs.dox.inc
348 * \ingroup logger_types
349 */
351{
352 /// The default level
354};
355
356/// Software INFO log entry
357/** \includedoc sw_logs.dox.inc
358 * Used to record a normal event or condition. This is the lowest priority used in normal operations.
359 * \ingroup logger_types
360 */
362{
363 /// The default level
365};
366
367/// Software DEBUG log entry
368/** \includedoc sw_logs.dox.inc
369 * \ingroup logger_types
370 */
372{
373 /// The default level
375};
376
377/// Software DEBUG2 log entry
378/** \includedoc sw_logs.dox.inc
379 * \ingroup logger_types
380 */
382{
383 /// The default level
385};
386
387} // namespace logger
388} // namespace MagAOX
389
390#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 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.