}
}
-static int log_print_line_format_json(int fd, const dlogutil_entry_s *entry, struct log_write_buffer *wrbuf)
-{
- size_t buflen;
- // TODO: This could really use an improvement
- char *const buf = log_format_json(wrbuf->data + wrbuf->position, wrbuf->size - wrbuf->position, entry, &buflen, entry->msg, entry->msg + entry->tag_len + 1);
- if (!buf)
- return -1;
- bool to_free = buf != (wrbuf->data + wrbuf->position);
-
- int res = resolve_write(fd, wrbuf, buf, buflen);
- if (to_free)
- free(buf);
- return res;
-}
-
#define METADATA_MAX_LEN 128
#define COLORED_METADATA_MAX_LEN (METADATA_MAX_LEN + sizeof COLOR_PURPLE + sizeof COLOR_RESET)
return result;
}
+static int log_print_line_format_json(int fd, const dlogutil_entry_s *entry, struct log_write_buffer *wrbuf)
+{
+ size_t buflen;
+ // TODO: This could really use an improvement
+ char *const buf = log_format_json(wrbuf->data + wrbuf->position, wrbuf->size - wrbuf->position, entry, &buflen, entry_get_tag_string(entry), entry_get_message_string(entry));
+ if (!buf)
+ return -1;
+ bool to_free = buf != (wrbuf->data + wrbuf->position);
+
+ int res = resolve_write(fd, wrbuf, buf, buflen);
+ if (to_free)
+ free(buf);
+ return res;
+}
+
/**
* @brief Print log line
* @details Prints the given log entry to the supplied file descriptor
{FORMAT_RECV_REALTIME, DLOG_INFO, false, "02-01 00:05:17.734 I/DLOG_ERROR_NOTAG(P 4228, T 4567): Tagless\n"},
{FORMAT_BRIEF , DLOG_INFO, false, "I/DLOG_ERROR_NOTAG( 4228): Tagless\n" },
{FORMAT_PROCESS , DLOG_INFO, false, "I( 4228) Tagless (DLOG_ERROR_NOTAG)\n" },
+ {FORMAT_JSON , DLOG_INFO, false, "{"
+ "\"priority\":\"info\","
+ "\"pid\":4228,"
+ "\"tid\":4567,"
+ "\"recv_real\":\"1970-02-01T00:05:17+0000\","
+ "\"recv_mono\":365467.346253662,"
+ "\"sent_real\":\"1970-03-14T23:22:51+0000\","
+ "\"sent_mono\":3205048.235123213,"
+ "\"tag\":\"DLOG_ERROR_NOTAG\","
+ "\"msg\":\"Tagless\""
+ "}\n"},
};
CHECK_LOGPRINT_TESTCASES("\0Tagless", tests_tagless);
{FORMAT_PROCESS, DLOG_INFO, false, "I( 4228) DLOG_ERROR_NOMSG (SOME_TAG)\n" },
{FORMAT_LONG , DLOG_INFO, false, "[ 03-14 23:22:51.451 I/SOME_TAG P 4228, T 4567]\n"
"DLOG_ERROR_NOMSG\n\n" },
+ {FORMAT_JSON , DLOG_INFO, false, "{"
+ "\"priority\":\"info\","
+ "\"pid\":4228,"
+ "\"tid\":4567,"
+ "\"recv_real\":\"1970-02-01T00:05:17+0000\","
+ "\"recv_mono\":365467.346253662,"
+ "\"sent_real\":\"1970-03-14T23:22:51+0000\","
+ "\"sent_mono\":3205048.235123213,"
+ "\"tag\":\"SOME_TAG\","
+ "\"msg\":\"DLOG_ERROR_NOMSG\""
+ "}\n"},
{FORMAT_BRIEF , DLOG_WARN, true, "\033[33;1mW/SOME_TAG( 4228): \033[0mDLOG_ERROR_NOMSG\n" },
{FORMAT_RAW , DLOG_WARN, true, "DLOG_ERROR_NOMSG\n" },