Syslogd from busybox allows logging of only the messages that have a
higher severity (i.e. lower value) than a specified limit.
This patch adds the same functionality to logread.
As -l is already used by logread, I chose -n.

Signed-off-by: Reiner Herrmann <[email protected]>
---
 log/logread.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/log/logread.c b/log/logread.c
index f677b44..6b14e1c 100644
--- a/log/logread.c
+++ b/log/logread.c
@@ -59,7 +59,7 @@ static struct uloop_timeout retry;
 static struct uloop_fd sender;
 static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file, 
*hostname;
 static int log_type = LOG_STDOUT;
-static int log_size, log_udp;
+static int log_size, log_udp, log_level=8;
 
 static const char* getcodetext(int value, CODE *codetable) {
        CODE *i;
@@ -134,11 +134,16 @@ static int log_notify(struct ubus_context *ctx, struct 
ubus_object *obj,
                }
        }
 
+       p = blobmsg_get_u32(tb[LOG_PRIO]);
+       if (LOG_PRI(p) >= log_level)
+               return 0;
+
        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);
+
+
        if (log_type == LOG_NET) {
                int err;
 
@@ -266,8 +271,11 @@ static void read_cb(struct ubus_request *req, int type, 
struct blob_attr *msg)
                if (!tb[LOG_MSG] || !tb[LOG_ID] || !tb[LOG_PRIO] || 
!tb[LOG_SOURCE] || !tb[LOG_TIME])
                        continue;
 
-               t = blobmsg_get_u64(tb[LOG_TIME]);
                p = blobmsg_get_u32(tb[LOG_PRIO]);
+               if (LOG_PRI(p) >= log_level)
+                       continue;
+
+               t = blobmsg_get_u64(tb[LOG_TIME]);
                c = ctime(&t);
                c[strlen(c) - 1] = '\0';
 
@@ -292,6 +300,7 @@ static int usage(const char *prog)
                "    -P <prefix>        Prefix custom text to streamed 
messages\n"
                "    -f                 Follow log messages\n"
                "    -u                 Use UDP as the protocol\n"
+               "    -n <level>         Read only messages more urgent than 
'level' (1-8)\n"
                "\n", prog);
        return 1;
 }
@@ -305,7 +314,7 @@ int main(int argc, char **argv)
        static struct blob_buf b;
        int retry = 5;
 
-       while ((ch = getopt(argc, argv, "ufs:l:r:F:p:S:P:h:")) != -1) {
+       while ((ch = getopt(argc, argv, "ufs:l:r:F:p:S:P:h:n:")) != -1) {
                switch (ch) {
                case 'u':
                        log_udp = 1;
@@ -341,6 +350,12 @@ int main(int argc, char **argv)
                case 'h':
                        hostname = optarg;
                        break;
+               case 'n':
+                       log_level = atoi(optarg);
+                       if (log_level < 1 || log_level > 8)
+                               log_level = 8;
+
+                       break;
                default:
                        return usage(*argv);
                }
-- 
1.9.0.rc3
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to