blob: 541ddb1754b081d23d117f36f4953f75af7a2f2d [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#include "aos/logging/queue_logging.h"
Brian Silvermand6974f42014-02-14 13:39:21 -08002
John Park33858a32018-09-28 23:05:48 -07003#include "aos/logging/interface.h"
4#include "aos/logging/sizes.h"
5#include "aos/queue_types.h"
Brian Silvermand6974f42014-02-14 13:39:21 -08006
7namespace aos {
8namespace logging {
Brian Silvermancb5da1f2015-12-05 22:19:58 -05009namespace internal {
Brian Silvermand6974f42014-02-14 13:39:21 -080010
Brian Silvermancb5da1f2015-12-05 22:19:58 -050011void 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 Schuh41d709b2015-11-21 22:38:46 -080014 {
15 auto fn = [&](LogImplementation *implementation) {
16 implementation->LogStruct(level, message, size, type, serialize);
17 };
Brian Silvermancb5da1f2015-12-05 22:19:58 -050018 RunWithCurrentImplementation(levels, ::std::ref(fn));
Austin Schuh41d709b2015-11-21 22:38:46 -080019 }
Brian Silvermanff12c9f2014-03-19 17:53:29 -070020
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 Silvermand6974f42014-02-14 13:39:21 -080035}
36
Brian Silvermancb5da1f2015-12-05 22:19:58 -050037} // namespace internal
Brian Silvermand6974f42014-02-14 13:39:21 -080038} // namespace logging
39} // namespace aos