| 1147 | }; |
| 1148 | |
| 1149 | static void log_to_json(struct timerel diff, |
| 1150 | enum log_level level, |
| 1151 | const struct node_id *node_id, |
| 1152 | const char *prefix, |
| 1153 | const char *log, |
| 1154 | size_t loglen, |
| 1155 | const u8 *io, |
| 1156 | size_t iolen, |
| 1157 | struct log_info *info) |
| 1158 | { |
| 1159 | if (info->node_id) { |
| 1160 | if (!node_id || !node_id_eq(node_id, info->node_id)) |
| 1161 | return; |
| 1162 | } |
| 1163 | |
| 1164 | if (level < info->level) { |
| 1165 | return; |
| 1166 | } |
| 1167 | |
| 1168 | json_object_start(info->response, NULL); |
| 1169 | json_add_string(info->response, "type", |
| 1170 | level == LOG_BROKEN ? "BROKEN" |
| 1171 | : level == LOG_UNUSUAL ? "UNUSUAL" |
| 1172 | : level == LOG_INFORM ? "INFO" |
| 1173 | : level == LOG_DBG ? "DEBUG" |
| 1174 | : level == LOG_TRACE ? "TRACE" |
| 1175 | : level == LOG_IO_IN ? "IO_IN" |
| 1176 | : level == LOG_IO_OUT ? "IO_OUT" |
| 1177 | : "UNKNOWN"); |
| 1178 | json_add_timestr(info->response, "time", diff.ts); |
| 1179 | if (node_id) |
| 1180 | json_add_node_id(info->response, "node_id", node_id); |
| 1181 | json_add_string(info->response, "source", prefix); |
| 1182 | json_add_stringn(info->response, "log", log, loglen); |
| 1183 | if (io) |
| 1184 | json_add_hex(info->response, "data", io, iolen); |
| 1185 | |
| 1186 | json_object_end(info->response); |
| 1187 | } |
| 1188 | |
| 1189 | void json_add_log(struct json_stream *response, |
| 1190 | const struct log_book *log_book, |
nothing calls this directly
no test coverage detected