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