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

Submitted by Ron Brash on July 11, 2017, 3:55 p.m.

Details

Message ID CAPZm7uXosO11=NZQo7dYpG-Y9NABybrm8Jg_gx8Rs9PyL0uayg@mail.gmail.com
State New
Headers show

Commit Message

Ron Brash July 11, 2017, 3:55 p.m.
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@gmail.com”>
---
 log/logd.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

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;