blob: 888f8083459f13e2ec711ce1a3150c4776738956 [file] [log] [blame]
Brian Silvermand6974f42014-02-14 13:39:21 -08001#ifndef AOS_COMMON_LOGGING_QUEUE_LOGGING_H_
2#define AOS_COMMON_LOGGING_QUEUE_LOGGING_H_
3
4#include <stdio.h>
5#include <stdlib.h>
6
Brian Silvermancb5da1f2015-12-05 22:19:58 -05007#include <functional>
Brian Silvermand6974f42014-02-14 13:39:21 -08008#include <string>
9
Brian Silvermancb5da1f2015-12-05 22:19:58 -050010#include "aos/common/logging/interface.h"
Brian Silvermanfd5e2a32014-02-22 20:02:39 -080011#include "aos/common/die.h"
Brian Silvermand6974f42014-02-14 13:39:21 -080012
13namespace aos {
14namespace logging {
15
Brian Silvermanfd5e2a32014-02-22 20:02:39 -080016// Logs the contents of a structure (or Queue message) and a constant string.
17// structure must be an instance of one of the generated queue types.
Brian Silvermancb5da1f2015-12-05 22:19:58 -050018#define LOG_STRUCT(level, message, structure) \
19 do { \
20 static const ::std::string kAosLoggingMessage( \
21 LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
22 ::aos::logging::DoLogStructTemplated(level, kAosLoggingMessage, \
23 structure); \
24 /* so that GCC knows that it won't return */ \
25 if (level == FATAL) { \
26 ::aos::Die("DoLogStruct(FATAL) fell through!!!!!\n"); \
27 } \
Brian Silvermand6974f42014-02-14 13:39:21 -080028 } while (false)
Brian Silvermand6974f42014-02-14 13:39:21 -080029
30template <class T>
Brian Silvermancb5da1f2015-12-05 22:19:58 -050031void DoLogStructTemplated(log_level level, const ::std::string &message,
32 const T &structure) {
33 auto fn = [&structure](char *buffer)
34 -> size_t { return structure.Serialize(buffer); };
35
36 internal::DoLogStruct(level, message, T::Size(), T::GetType(), ::std::ref(fn),
37 1);
38}
Brian Silvermand6974f42014-02-14 13:39:21 -080039
40} // namespace logging
41} // namespace aos
42
Brian Silvermand6974f42014-02-14 13:39:21 -080043#endif // AOS_COMMON_LOGGING_QUEUE_LOGGING_H_