blob: 6173074fcb0b5f69bb459e802a13bac44eec8606 [file] [log] [blame]
Brian Silvermanfd5e2a32014-02-22 20:02:39 -08001#include "aos/common/logging/matrix_logging.h"
Brian Silvermanff12c9f2014-03-19 17:53:29 -07002
3#include "aos/common/queue_types.h"
4
5namespace aos {
6namespace logging {
7
8void LogImplementation::DoLogMatrix(log_level level,
9 const ::std::string &message,
10 uint32_t type_id, int rows, int cols,
11 const void *data, int levels) {
12 internal::RunWithCurrentImplementation(
13 levels, [&](LogImplementation * implementation) {
14 implementation->LogMatrix(level, message, type_id, rows, cols, data);
15 });
16
17 if (level == FATAL) {
18 char serialized[1024];
19 if (static_cast<size_t>(rows * cols * MessageType::Sizeof(type_id)) >
20 sizeof(serialized)) {
21 Die("LOG(FATAL) matrix too big to serialize");
22 }
23 SerializeMatrix(type_id, serialized, data, rows, cols);
24 char printed[LOG_MESSAGE_LEN];
25 size_t printed_bytes = sizeof(printed);
26 if (!PrintMatrix(printed, &printed_bytes, serialized, type_id, rows, cols)) {
27 Die("LOG(FATAL) PrintMatrix call failed");
28 }
29 Die("%.*s: %.*s\n", static_cast<int>(message.size()), message.data(),
30 static_cast<int>(printed_bytes), printed);
31 }
32}
33
34} // namespace logging
35} // namespace aos