John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 1 | #ifndef AOS_LOGGING_QUEUE_LOGGING_H_ |
| 2 | #define AOS_LOGGING_QUEUE_LOGGING_H_ |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 7 | #include <functional> |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 8 | #include <string> |
| 9 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 10 | #include "aos/logging/interface.h" |
| 11 | #include "aos/die.h" |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 12 | |
| 13 | namespace aos { |
| 14 | namespace logging { |
| 15 | |
Brian Silverman | fd5e2a3 | 2014-02-22 20:02:39 -0800 | [diff] [blame] | 16 | // 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 Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 18 | #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 Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 28 | } while (false) |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 29 | |
| 30 | template <class T> |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 31 | void 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 Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 39 | |
| 40 | } // namespace logging |
| 41 | } // namespace aos |
| 42 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 43 | #endif // AOS_LOGGING_QUEUE_LOGGING_H_ |