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 "generated/software_log_generated.h"
14#include "flatbuffer_log.hpp"
15
16namespace MagAOX
17{
18namespace logger
19{
20
21///Base class for software logs
22/** Such logs are used to log software status, warnings, and errors. Does not have defaultLevel, so this can not be used as a log type in logger.
23 *
24 * \includedoc sw_logs.dox.inc
25 *
26 *
27 * \ingroup logger_types__basic
28 */
30{
31 ///The event code
32 static const flatlogs::eventCodeT eventCode = eventCodes::SOFTWARE_LOG;
33
34 ///The type of the message
35 struct messageT : public fbMessage
36 {
37 /// C'tor with full specification.
38 messageT( const char * file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
39 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
40 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be passed here, so strerror can be used later.
41 const int32_t otherCode, ///< [in] Some other error code, such as a return value or library code.
42 const char * explanation ///< [in] explanatory text about the software event
43 )
44 {
45 auto _file = builder.CreateString(file);
46 auto _expl = builder.CreateString(explanation);
47
48 auto gs = CreateSoftware_log_fb(builder, _file, line, errnoCode, otherCode, _expl);
49 builder.Finish(gs);
50 }
51
52 /// C'tor with full specification, overloaded for a std::string in explanation.
53 /** \overload
54 */
55 messageT( const char * file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
56 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
57 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be passed here, so strerror can be used later.
58 const int32_t otherCode, ///< [in] Some other error code, such as a return value or library code.
59 const std::string & explanation ///< [in] explanatory text about the software event
60 )
61 {
62 auto _file = builder.CreateString(file);
63 auto _expl = builder.CreateString(explanation);
64
65 auto gs = CreateSoftware_log_fb(builder, _file, line, errnoCode, otherCode, _expl);
66 builder.Finish(gs);
67 }
68
69 /// C'tor for errno only -- code explanation can be looked up later.
70 messageT( const char * file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
71 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
72 const int32_t errnoCode ///< [in] The errno code at the time of the log entry. Only errno should be passed here, so strerror can be used later.
73 )
74 {
75 auto _file = builder.CreateString(file);
76
77 auto gs = CreateSoftware_log_fb(builder, _file, line, errnoCode, 0, 0);
78 builder.Finish(gs);
79 }
80
81 /// C'tor for errno with additional explanation.
82 messageT( const char * file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
83 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
84 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be passed here, so strerror can be used later.
85 const char * explanation ///< [in] explanatory text about the software event
86 )
87 {
88 auto _file = builder.CreateString(file);
89 auto _expl = builder.CreateString(explanation);
90
91 auto gs = CreateSoftware_log_fb(builder, _file, line, errnoCode, 0, _expl);
92 builder.Finish(gs);
93 }
94
95 /// C'tor for errno with additional explanation, std::string overload.
96 messageT( const char * file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
97 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
98 const int32_t errnoCode, ///< [in] The errno code at the time of the log entry. Only errno should be passed here, so strerror can be used later.
99 const std::string & explanation ///< [in] explanatory text about the software event
100 )
101 {
102 auto _file = builder.CreateString(file);
103 auto _expl = builder.CreateString(explanation);
104
105 auto gs = CreateSoftware_log_fb(builder, _file, line, errnoCode, 0, _expl);
106 builder.Finish(gs);
107 }
108
109 /// C'tor with no codes, just the explanation.
110 messageT( const char * file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
111 const uint32_t line, ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
112 const std::string & explanation ///< [in] explanatory text about the software event
113 )
114 {
115 auto _file = builder.CreateString(file);
116 auto _expl = builder.CreateString(explanation);
117
118 auto gs = CreateSoftware_log_fb(builder, _file, line, 0,0,_expl);
119 builder.Finish(gs);
120 }
121
122 /// C'tor for a trace log, only the file and line.
123 messageT( const char * file, ///< [in] The file of the error, should always be \c \_\_FILE\_\_
124 const uint32_t line ///< [in] The line number of the error, should always be \c \_\_LINE\_\_
125 )
126 {
127 auto _file = builder.CreateString(file);
128
129 auto gs = CreateSoftware_log_fb(builder, _file, line, 0,0,0);
130 builder.Finish(gs);
131 }
132
133
134 };
135
136 static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
137 flatlogs::msgLenT len ///< [in] length of msgBuffer.
138 )
139 {
140 auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
141 return VerifySoftware_log_fbBuffer(verifier);
142 }
143
144 ///Get the message formatted for human consumption.
145 static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
146 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
147 )
148 {
149
150 static_cast<void>(len);
151
152 auto rgs = GetSoftware_log_fb(msgBuffer);
153
154 std::string ret = "SW FILE: ";
155 if(rgs->file() != nullptr)
156 {
157 ret += rgs->file()->c_str();
158 }
159 else
160 {
161 ret += "????";
162 }
163
164 ret += " LINE: ";
165 ret += mx::ioutils::convertToString(rgs->line());
166 if(rgs->errnoCode())
167 {
168 ret += " ERRNO: ";
169 ret += mx::ioutils::convertToString(rgs->errnoCode());
170 ret += " [";
171 ret += strerror(rgs->errnoCode());
172 ret += "]";
173 }
174 if(rgs->otherCode())
175 {
176 ret += " CODE: ";
177 ret += mx::ioutils::convertToString(rgs->otherCode());
178 if(rgs->explanation())
179 {
180 ret += " [";
181 ret += rgs->explanation()->c_str();
182 ret += "]";
183 }
184 }
185 else if(rgs->explanation())
186 {
187 ret += " >";
188 ret += rgs->explanation()->c_str();
189 }
190 return ret;
191 }
192
193};
194
195
196///Software EMERGENCY log entry
197/** This should only be used for a system-wide emergency requiring operator or automatic shutdown. Not for a process specific problem.
198 * \includedoc sw_logs.dox.inc
199 * \ingroup logger_types
200 */
202{
203 ///The default level
205};
206
207///Software ALERT log entry
208/** This should only be used for a system-wide emergency requiring operator or automatic action. Not for a process specific problem.
209 * \includedoc sw_logs.dox.inc
210 * \ingroup logger_types
211 */
213{
214 ///The default level
216};
217
218///Software CRITICAL log entry
219/** This should only be used if the process is going to shutdown.
220 * \includedoc sw_logs.dox.inc
221 * \ingroup logger_types
222 */
224{
225 ///The default level
227};
228
229///Software ERR log entry
230/** Used to record and error that the process will attempt to recover from.
231 * \includedoc sw_logs.dox.inc
232 * \ingroup logger_types
233 */
235{
236 ///The default level
238};
239
240///Software WARN log entry
241/** Used to record an abnormal condition.
242 * \includedoc sw_logs.dox.inc
243 * \ingroup logger_types
244 */
246{
247 ///The default level
249};
250
251///Software NOTICE log entry
252/** Used to record a normal but signficant event or condition.
253 * \includedoc sw_logs.dox.inc
254 * \ingroup logger_types
255 */
257{
258 ///The default level
260};
261
262///Software INFO log entry
263/** \includedoc sw_logs.dox.inc
264 * Used to record a normal event or condition. This is the lowest priority used in normal operations.
265 * \ingroup logger_types
266 */
268{
269 ///The default level
271};
272
273///Software DEBUG log entry
274/** \includedoc sw_logs.dox.inc
275 * \ingroup logger_types
276 */
278{
279 ///The default level
281};
282
283///Software DEBUG2 log entry
284/** \includedoc sw_logs.dox.inc
285 * \ingroup logger_types
286 */
288{
289 ///The default level
291};
292
293} //namespace logger
294} //namespace MagAOX
295
296#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
Definition dm.hpp:24
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 char *file, const uint32_t line)
C'tor for a trace log, only the file and line.
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 char *file, const uint32_t line, const int32_t errnoCode, const char *explanation)
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.
Software NOTICE log entry.
static const flatlogs::logPrioT defaultLevel
The default level.
Software WARN log entry.
static const flatlogs::logPrioT defaultLevel
The default level.