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
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
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 += std::format(" LINE: {}",rgs->line());
165
166 if(rgs->errnoCode())
167 {
168 ret += std::format(" ERRNO: {} [{}]",rgs->errnoCode(),rgs->errnoCode());
169 }
170 if(rgs->otherCode())
171 {
172 ret += std::format(" CODE: {}",rgs->otherCode());
173 if(rgs->explanation())
174 {
175 ret += std::format(" [{}]",rgs->explanation()->c_str());
176 }
177 }
178 else if(rgs->explanation())
179 {
180 ret += " >";
181 ret += rgs->explanation()->c_str();
182 }
183 return ret;
184 }
185
186 /// Get an empty logMetaDetail because meta data doesn't make sense for this log
187 /**
188 * \returns an empty logMetaDetail
189 */
190 static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
191 {
192 static_cast<void>(member);
193
194 std::cerr << "meta data doesn't make sense for software_log.\n";
195 return logMetaDetail();
196 }
197
198};
199
200
201///Software EMERGENCY log entry
202/** This should only be used for a system-wide emergency requiring operator or automatic shutdown. Not for a process specific problem.
203 * \includedoc sw_logs.dox.inc
204 * \ingroup logger_types
205 */
207{
208 ///The default level
210};
211
212///Software ALERT log entry
213/** This should only be used for a system-wide emergency requiring operator or automatic action. Not for a process specific problem.
214 * \includedoc sw_logs.dox.inc
215 * \ingroup logger_types
216 */
218{
219 ///The default level
221};
222
223///Software CRITICAL log entry
224/** This should only be used if the process is going to shutdown.
225 * \includedoc sw_logs.dox.inc
226 * \ingroup logger_types
227 */
229{
230 ///The default level
232};
233
234///Software ERR log entry
235/** Used to record and error that the process will attempt to recover from.
236 * \includedoc sw_logs.dox.inc
237 * \ingroup logger_types
238 */
240{
241 ///The default level
243};
244
245///Software WARN log entry
246/** Used to record an abnormal condition.
247 * \includedoc sw_logs.dox.inc
248 * \ingroup logger_types
249 */
251{
252 ///The default level
254};
255
256///Software NOTICE log entry
257/** Used to record a normal but signficant event or condition.
258 * \includedoc sw_logs.dox.inc
259 * \ingroup logger_types
260 */
262{
263 ///The default level
265};
266
267///Software INFO log entry
268/** \includedoc sw_logs.dox.inc
269 * Used to record a normal event or condition. This is the lowest priority used in normal operations.
270 * \ingroup logger_types
271 */
273{
274 ///The default level
276};
277
278///Software DEBUG log entry
279/** \includedoc sw_logs.dox.inc
280 * \ingroup logger_types
281 */
283{
284 ///The default level
286};
287
288///Software DEBUG2 log entry
289/** \includedoc sw_logs.dox.inc
290 * \ingroup logger_types
291 */
293{
294 ///The default level
296};
297
298} //namespace logger
299} //namespace MagAOX
300
301#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:28
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.
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.