diff mbox

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

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

Commit Message

Ron Brash July 11, 2017, 3:55 p.m. UTC
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(-)

Comments

John Crispin Nov. 8, 2017, 7:58 a.m. UTC | #1
On 11/07/17 17:55, Ron Brash wrote:
> 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.
>
sorry for the late review ...

> Signed-off-by: “Ron Brash <“ron.brash@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;
make this static and remove the = 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;
> +       }

drop the brackets please and use the LOG_PRI() macro please

>          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;
> +                       }
you can probably drop the validation. if the users passes 9 as a 
priority everything will be logged. passing -1 will cause silent logging.

     John

> +                       break;
>                  }
>          }
>          log_size *= 1024;
>
> _______________________________________________
> Lede-dev mailing list
> Lede-dev@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/lede-dev
David Lang Nov. 8, 2017, 7:40 p.m. UTC | #2
On Wed, 8 Nov 2017, John Crispin wrote:

> you can probably drop the validation. if the users passes 9 as a 
> priority everything will be logged. passing -1 will cause silent logging.

you should do limit checks and cap the internal value to the limit, otherwise 
you have to do more work for each log message than a simple mask and unsigned 
compare.
diff mbox

Patch

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;