From: John Crispin Date: Wed, 19 Jun 2013 20:14:57 +0000 (+0200) Subject: make add facility and level to logread output X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fprocd.git;a=commitdiff_plain;h=c23413feeb5179911d623e6ffb84b36671652788 make add facility and level to logread output Signed-off-by: John Crispin --- diff --git a/logread.c b/logread.c index 3b73305..5d1be68 100644 --- a/logread.c +++ b/logread.c @@ -16,6 +16,9 @@ #include #include +#define SYSLOG_NAMES +#include + #include #include #include @@ -59,6 +62,7 @@ static int log_notify(struct ubus_context *ctx, struct ubus_object *obj, { struct blob_attr *tb[__LOG_MAX]; char buf[256]; + uint32_t p; char *str; time_t t; char *c; @@ -69,10 +73,13 @@ static int log_notify(struct ubus_context *ctx, struct ubus_object *obj, t = blobmsg_get_u64(tb[LOG_TIME]) / 1000; c = ctime(&t); + p = blobmsg_get_u32(tb[LOG_PRIO]); c[strlen(c) - 1] = '\0'; str = blobmsg_format_json(msg, true); - snprintf(buf, sizeof(buf), "%s - %s: %s\n", - c, (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("syslog") : ("kernel"), method); + snprintf(buf, sizeof(buf), "%s %s.%s%s %s\n", + c, facilitynames[LOG_FAC(p)].c_name, prioritynames[LOG_PRI(p)].c_name, + (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : (" kernel:"), + method); write(sender.fd, buf, strlen(buf)); free(str); @@ -138,6 +145,7 @@ static void read_cb(struct ubus_request *req, int type, struct blob_attr *msg) return; blobmsg_for_each_attr(cur, _tb[READ_LINE], rem) { struct blob_attr *tb[__LOG_MAX]; + uint32_t p; char *c; if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) @@ -148,10 +156,13 @@ static void read_cb(struct ubus_request *req, int type, struct blob_attr *msg) continue; t = blobmsg_get_u64(tb[LOG_TIME]); + p = blobmsg_get_u32(tb[LOG_PRIO]); c = ctime(&t); c[strlen(c) - 1] = '\0'; - printf("%s - %s: %s\n", - c, (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("syslog") : ("kernel"), + + printf("%s %s.%s%s %s\n", + c, facilitynames[LOG_FAC(p)].c_name, prioritynames[LOG_PRI(p)].c_name, + (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : (" kernel:"), blobmsg_get_string(tb[LOG_MSG])); } }