API
string_log.hpp
Go to the documentation of this file.
1 /** \file string_log.hpp
2  * \brief The MagAO-X logger string_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_string_log_hpp
11 #define logger_types_string_log_hpp
12 
13 #include "generated/string_log_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 
19 namespace logger
20 {
21 
22 
23 
24 /// Base class for logs consisting of a string message.
25 /** Does not have eventCode or defaultLevel, so this can not be used as a log type in logger.
26  *
27  * \ingroup logger_types_basic
28  */
29 struct string_log : public flatbuffer_log
30 {
31  ///The type of the message
32  struct messageT : public fbMessage
33  {
34  messageT( const char * msg )
35  {
36  auto _msg = builder.CreateString(msg);
37 
38  auto gs = CreateString_log_fb(builder, _msg);
39  builder.Finish(gs);
40  }
41 
42  messageT( const std::string & msg )
43  {
44  auto _msg = builder.CreateString(msg);
45 
46  auto gs = CreateString_log_fb(builder, _msg);
47  builder.Finish(gs);
48  }
49  };
50 
51  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
52  flatlogs::msgLenT len ///< [in] length of msgBuffer.
53  )
54  {
55  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
56  return VerifyString_log_fbBuffer(verifier);
57  }
58 
59  ///Get the message formatted for human consumption.
60  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
61  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
62  )
63  {
64  static_cast<void>(len);
65 
66  auto rgs = GetString_log_fb(msgBuffer);
67 
68  if(rgs->message() == nullptr) return "";
69  else return rgs->message()->c_str();
70  }
71 
72 };
73 
74 
75 
76 
77 } //namespace logger
78 } //namespace MagAOX
79 
80 #endif //logger_types_string_log_hpp
The MagAO-X logger flatbuffer log base type.
msgLen2T msgLenT
The type used to refer to the message length, regardless of length.
Definition: logDefs.hpp:69
static void * messageBuffer(bufferPtrT &logBuffer)
Get the message buffer address.
Definition: logHeader.hpp:621
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition: logHeader.hpp:58
std::stringstream msg
Definition: dm.hpp:24
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
The type of the message.
Definition: string_log.hpp:33
messageT(const std::string &msg)
Definition: string_log.hpp:42
Base class for logs consisting of a string message.
Definition: string_log.hpp:30
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
Definition: string_log.hpp:51
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatted for human consumption.
Definition: string_log.hpp:60