diff --git a/crashlog.c b/crashlog.c index 16f73d7..e9d7487 100644 --- a/crashlog.c +++ b/crashlog.c @@ -31,9 +31,9 @@ crashlog_init(void) if (tb[CRASH_LOG]) crashlog_send(tb[CRASH_LOG]); else - log_send("failed to parse the crashlog"); + log_send("failed to parse the crashlog", LOG_ERR); } else { - log_send("found a crashlog that is not valid json"); + log_send("found a crashlog that is not valid json", LOG_ERR); } blob_buf_free(&crashlog); unlink(CRASHLOG); diff --git a/proto.c b/proto.c index 38b976e..3ab646a 100644 --- a/proto.c +++ b/proto.c @@ -120,7 +120,7 @@ connect_send(void) blobmsg_add_u64(&proto, "uuid", uuid_active ? uuid_active : 1); c = blobmsg_open_table(&proto, "capabilities"); if (!blobmsg_add_json_from_file(&proto, path)) { - log_send("failed to load capabilities"); + log_send("failed to load capabilities", LOG_ERR); return; } blobmsg_close_table(&proto, c); @@ -305,13 +305,13 @@ stats_send(struct blob_attr *a) } void -log_send(char *message) +log_send(char *message, int severity) { void *m = proto_new_blob("log"); blobmsg_add_string(&proto, "serial", client.serial); blobmsg_add_string(&proto, "log", message); - blobmsg_add_u32(&proto, "severity", LOG_INFO); + blobmsg_add_u32(&proto, "severity", severity); blobmsg_close_table(&proto, m); ULOG_ERR("%s\n", message); proto_send_blob(); @@ -670,7 +670,7 @@ proto_handle_blob(void) if (!rpc[JSONRPC_VER] || (!rpc[JSONRPC_METHOD] && !rpc[JSONRPC_ERROR]) || (rpc[JSONRPC_METHOD] && !rpc[JSONRPC_PARAMS]) || strcmp(blobmsg_get_string(rpc[JSONRPC_VER]), "2.0")) { - log_send("received invalid jsonrpc call"); + log_send("received invalid jsonrpc call", LOG_ERR); return; } @@ -708,7 +708,7 @@ proto_handle(char *cmd) blob_buf_init(&proto, 0); if (!blobmsg_add_json_from_string(&proto, cmd)) { - log_send("failed to parse command"); + log_send("failed to parse command", LOG_CRIT); return; } proto_handle_blob(); diff --git a/ubus.c b/ubus.c index 3afc1f9..09a3243 100644 --- a/ubus.c +++ b/ubus.c @@ -38,11 +38,13 @@ static int ubus_send_cb(struct ubus_context *ctx, enum { LOG_MSG, + LOG_SEVERITY, __LOG_MAX, }; static const struct blobmsg_policy log_policy[__LOG_MAX] = { [LOG_MSG] = { .name = "msg", .type = BLOBMSG_TYPE_STRING }, + [LOG_SEVERITY] = { .name = "severity", .type = BLOBMSG_TYPE_INT32 }, }; static int ubus_log_cb(struct ubus_context *ctx, @@ -51,12 +53,16 @@ static int ubus_log_cb(struct ubus_context *ctx, const char *method, struct blob_attr *msg) { struct blob_attr *tb[__LOG_MAX] = {}; + int severity = LOG_INFO; blobmsg_parse(log_policy, __LOG_MAX, tb, blobmsg_data(msg), blobmsg_data_len(msg)); if (!tb[LOG_MSG]) return UBUS_STATUS_INVALID_ARGUMENT; - log_send(blobmsg_get_string(tb[LOG_MSG])); + if (tb[LOG_SEVERITY]) + severity = blobmsg_get_u32(tb[LOG_SEVERITY]); + + log_send(blobmsg_get_string(tb[LOG_MSG]), severity); return UBUS_STATUS_OK; } diff --git a/ucentral.h b/ucentral.h index 892429f..b24690c 100644 --- a/ucentral.h +++ b/ucentral.h @@ -69,7 +69,7 @@ int cmd_run(struct blob_attr *tb, uint32_t id); void connect_send(void); void ping_send(void); void raw_send(struct blob_attr *a); -void log_send(char *message); +void log_send(char *message, int severity); void health_send(uint32_t sanity, struct blob_attr *a); void result_send(uint32_t id, struct blob_attr *a, uint32_t uuid); void result_send_error(uint32_t error, char *text, uint32_t retcode, uint32_t id); diff --git a/upload.c b/upload.c index 7b35644..e8b13ac 100644 --- a/upload.c +++ b/upload.c @@ -36,10 +36,10 @@ upload_complete_cb(struct task *t, time_t uuid, uint32_t id, int ret) if (ret) { ULOG_ERR("ucentral: curl returned (%d)", ret); - log_send("failed to upload file"); + log_send("failed to upload file", LOG_ERR); return; } - log_send("upload complete"); + log_send("upload complete", LOG_INFO); } struct task upload_task = { @@ -67,7 +67,7 @@ upload_run(struct blob_attr *a) uint32_t id = 0; if (upload_pending) { - log_send("could not upload file due to another pending upload"); + log_send("could not upload file due to another pending upload", LOG_WARNING); return; } @@ -75,7 +75,7 @@ upload_run(struct blob_attr *a) blobmsg_data_len(a)); if (!tb[UPLOAD_UUID] || !tb[UPLOAD_FILE] || !tb[UPLOAD_URI]) { - log_send("invalid upload request"); + log_send("invalid upload request", LOG_ERR); return; }