blob: 021da7c5e44f3a268ab7a2e7aba43d4c9e0c3cb2 [file] [log] [blame]
Brian Silvermanfd5e2a32014-02-22 20:02:39 -08001#include "aos/common/logging/queue_logging.h"
Brian Silvermand6974f42014-02-14 13:39:21 -08002
Brian Silvermanfd5e2a32014-02-22 20:02:39 -08003#include "aos/common/logging/logging_impl.h"
Brian Silvermand6974f42014-02-14 13:39:21 -08004#include "aos/common/queue_types.h"
5
6namespace aos {
7namespace logging {
8
9void 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);
16
17 if (level == FATAL) {
18 char serialized[1024];
19 if (size > sizeof(serialize)) {
20 Die("LOG(FATAL) structure too big to serialize");
21 }
22 size_t used = serialize(serialized);
23 char printed[LOG_MESSAGE_LEN];
24 size_t printed_bytes = sizeof(printed);
25 if (!PrintMessage(printed, &printed_bytes, serialized, &used, *type)) {
26 Die("LOG(FATAL) PrintMessage call failed");
27 }
28 Die("%.*s: %.*s\n", static_cast<int>(message.size()), message.data(),
29 static_cast<int>(printed_bytes), printed);
30 }
31 });
32}
33
34} // namespace logging
35} // namespace aos