[LEDE-DEV] [PATCH][ubox] Add log priority filtering to daemon

Ron Brash ron.brash at gmail.com
Tue Jul 11 08:55:47 PDT 2017


After wanting to filter logs at the logger level, instead of post
log-write, we added
a feature such that we can filter within the logd daemon itself.


Signed-off-by: “Ron Brash <“ron.brash at gmail.com”>
---
 log/logd.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/log/logd.c b/log/logd.c
index 07aee2b..5b99fdf 100644
--- a/log/logd.c
+++ b/log/logd.c
@@ -27,6 +27,7 @@
 #include "syslog.h"

 int debug = 0;
+int priority = 0;
 static struct blob_buf b;
 static struct ubus_auto_conn conn;
 static LIST_HEAD(clients);
@@ -182,6 +183,9 @@ ubus_notify_log(struct log_head *l)
        if (list_empty(&clients))
                return;

+       if((l->priority & 7) > priority) {
+               return;
+       }
        blob_buf_init(&b, 0);
        blobmsg_add_string(&b, "msg", l->data);
        blobmsg_add_u32(&b, "id", l->id);
@@ -214,13 +218,21 @@ main(int argc, char **argv)
        int ch, log_size = 16;

        signal(SIGPIPE, SIG_IGN);
-       while ((ch = getopt(argc, argv, "S:")) != -1) {
+       while ((ch = getopt(argc, argv, "P:S:")) != -1) {
                switch (ch) {
                case 'S':
                        log_size = atoi(optarg);
                        if (log_size < 1)
                                log_size = 16;
                        break;
+               case 'P':
+                       priority = atoi(optarg);
+                       if (priority < 0) {
+                               priority = 0;
+                       } else if (priority > 7) {
+                               priority = 7;
+                       }
+                       break;
                }
        }
        log_size *= 1024;



More information about the Lede-dev mailing list