John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 1 | #include "aos/logging/queue_logging.h" |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 2 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 3 | #include "aos/logging/interface.h" |
| 4 | #include "aos/logging/sizes.h" |
| 5 | #include "aos/queue_types.h" |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 6 | |
| 7 | namespace aos { |
| 8 | namespace logging { |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 9 | namespace internal { |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 10 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 11 | void DoLogStruct(log_level level, const ::std::string &message, size_t size, |
| 12 | const MessageType *type, |
| 13 | const ::std::function<size_t(char *)> &serialize, int levels) { |
Austin Schuh | 41d709b | 2015-11-21 22:38:46 -0800 | [diff] [blame] | 14 | { |
| 15 | auto fn = [&](LogImplementation *implementation) { |
| 16 | implementation->LogStruct(level, message, size, type, serialize); |
| 17 | }; |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 18 | RunWithCurrentImplementation(levels, ::std::ref(fn)); |
Austin Schuh | 41d709b | 2015-11-21 22:38:46 -0800 | [diff] [blame] | 19 | } |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 20 | |
| 21 | if (level == FATAL) { |
| 22 | char serialized[1024]; |
| 23 | if (size > sizeof(serialized)) { |
| 24 | Die("LOG(FATAL) structure too big to serialize"); |
| 25 | } |
| 26 | size_t used = serialize(serialized); |
| 27 | char printed[LOG_MESSAGE_LEN]; |
| 28 | size_t printed_bytes = sizeof(printed); |
| 29 | if (!PrintMessage(printed, &printed_bytes, serialized, &used, *type)) { |
| 30 | Die("LOG(FATAL) PrintMessage call failed"); |
| 31 | } |
| 32 | Die("%.*s: %.*s\n", static_cast<int>(message.size()), message.data(), |
| 33 | static_cast<int>(printed_bytes), printed); |
| 34 | } |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 37 | } // namespace internal |
Brian Silverman | d6974f4 | 2014-02-14 13:39:21 -0800 | [diff] [blame] | 38 | } // namespace logging |
| 39 | } // namespace aos |