diff options
author | John Crispin <blogic@openwrt.org> | 2013-06-19 22:14:57 +0200 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2013-06-19 22:37:35 +0200 |
commit | c23413feeb5179911d623e6ffb84b36671652788 (patch) | |
tree | 3e0e3842a8a92dd165ddc66473738b51b6ee25ec | |
parent | 797613e67ca48004141be4d6112c01e62d12d413 (diff) | |
download | unitd-c23413feeb5179911d623e6ffb84b36671652788.tar unitd-c23413feeb5179911d623e6ffb84b36671652788.zip |
make add facility and level to logread output
Signed-off-by: John Crispin <blogic@openwrt.org>
-rw-r--r-- | logread.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -16,6 +16,9 @@ #include <unistd.h> #include <stdio.h> +#define SYSLOG_NAMES +#include <syslog.h> + #include <libubox/blobmsg_json.h> #include <libubox/usock.h> #include <libubox/uloop.h> @@ -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])); } } |