]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
log: add -D option to filter out debug logs
authorVincent Bernat <bernat@luffy.cx>
Sun, 16 Dec 2012 14:58:14 +0000 (15:58 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sun, 16 Dec 2012 15:04:58 +0000 (16:04 +0100)
The list of accepted tokens is documented in the manual page.

src/daemon/agent.c
src/daemon/interfaces.c
src/daemon/lldpd.8
src/daemon/lldpd.c
src/lib/atom-private.c
src/log.c
src/log.h

index 0c06a479c154b4a1a932e65f65c789d382550819..c33fea5e3011768acc77cdd635de521da60cd1db 100644 (file)
@@ -1813,14 +1813,14 @@ agent_log_callback(int major, int minor,
 
   if (msg && msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = '\0';
   switch (slm->priority) {
-  case LOG_EMERG:   log_warnx("snmp", "%s", msg?msg:slm->msg); break;
-  case LOG_ALERT:   log_warnx("snmp", "%s", msg?msg:slm->msg); break;
-  case LOG_CRIT:    log_warnx("snmp", "%s", msg?msg:slm->msg); break;
-  case LOG_ERR:     log_warnx("snmp", "%s", msg?msg:slm->msg); break;
-  case LOG_WARNING: log_warnx("snmp", "%s", msg?msg:slm->msg); break;
-  case LOG_NOTICE:  log_info ("snmp", "%s", msg?msg:slm->msg); break;
-  case LOG_INFO:    log_info ("snmp", "%s", msg?msg:slm->msg); break;
-  case LOG_DEBUG:   log_debug("snmp", "%s", msg?msg:slm->msg); break;
+  case LOG_EMERG:   log_warnx("libsnmp", "%s", msg?msg:slm->msg); break;
+  case LOG_ALERT:   log_warnx("libsnmp", "%s", msg?msg:slm->msg); break;
+  case LOG_CRIT:    log_warnx("libsnmp", "%s", msg?msg:slm->msg); break;
+  case LOG_ERR:     log_warnx("libsnmp", "%s", msg?msg:slm->msg); break;
+  case LOG_WARNING: log_warnx("libsnmp", "%s", msg?msg:slm->msg); break;
+  case LOG_NOTICE:  log_info ("libsnmp", "%s", msg?msg:slm->msg); break;
+  case LOG_INFO:    log_info ("libsnmp", "%s", msg?msg:slm->msg); break;
+  case LOG_DEBUG:   log_debug("libsnmp", "%s", msg?msg:slm->msg); break;
   }
   free(msg);
   return SNMP_ERR_NOERROR;
index c8533c0e86a12f4bc9c2fb0ae39f77094482378d..7978d5260bdfc60c0ce53085ac84950e71e17193 100644 (file)
@@ -507,7 +507,7 @@ iface_minimal_checks(struct lldpd *cfg, struct ifaddrs *ifa)
                return 0;
        }
 
-       log_debug("interface", "%s passes the minimal checks",
+       log_debug("interfaces", "%s passes the minimal checks",
            ifa->ifa_name);
        return 1;
 }
@@ -968,7 +968,7 @@ lldpd_ifh_bond(struct lldpd *cfg, struct ifaddrs *ifap)
                if ((master = iface_is_enslaved(cfg, ifa->ifa_name)) == -1)
                        continue;
 
-               log_debug("interface", "%s is an acceptable bonded device (master=%d)",
+               log_debug("interfaces", "%s is an acceptable bonded device (master=%d)",
                    ifa->ifa_name, master);
                if ((hardware = lldpd_get_hardware(cfg,
                            ifa->ifa_name,
index ef97de634c7486f501d044565e30d5f56276f03d..5c7cd7ec5137439fdd379a1cc9609e3a7160535c 100644 (file)
@@ -22,6 +22,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl dxcseiklrv
+.Op Fl D Ar debug
 .Op Fl S Ar description
 .Op Fl P Ar platform
 .Op Fl X Ar socket
@@ -59,7 +60,62 @@ If this option is specified,
 .Nm
 will run in the foreground and log to
 .Em stderr .
-This option can be specified many times to increase verbosity.
+This option can be specified many times to increase verbosity. When
+specified three times, debug logs will be enabled. They can be
+filtered with
+.Fl D
+flag.
+.It Fl D Ar debug
+This option allows the user to filter out debugging information by
+specifying allowed tokens. This option can be repeated several times
+to allow several tokens. This option must be combined with the
+.Fl d
+flag to have some effect. Only debugging logs can be filtered. Here is
+a list of allowed tokens with their description:
+.Bl -tag -width "XXXXXXXXXX" -offset "XXXX" -compact
+.It Sy main
+Main daemon.
+.It Sy interfaces
+Discovery of local interfaces.
+.It Sy lldp
+LLDP PDU encoding/decoding.
+.It Sy edp
+EDP PDU encoding/decoding.
+.It Sy cdp
+CDP/FDP PDU encoding/decoding.
+.It Sy sonmp
+SONMP PDU encoding/decoding.
+.It Sy event
+Events management.
+.It Sy libevent
+Events management but for logs generated by libevent.
+.It Sy privsep
+Privilege separation.
+.It Sy localchassis
+Retrieval of information related to the local chassis.
+.It Sy rpc
+Client communication.
+.It Sy control
+Management of the Unix control socket.
+.It Sy snmp
+SNMP subagent.
+.It Sy libsnmp
+SNMP subagent but for logs generated by NetSNMP.
+.It Sy decode
+Generic PDU decoding.
+.It Sy marshal
+Low-level serialization mechanisms.
+.It Sy alloc
+Low-level allocation mechanisms.
+.It Sy send
+Sending PDU to some interface.
+.It Sy receive
+Receiving PDU from some interface.
+.It Sy loop
+Main loop.
+.It Sy smartfilter
+Smart filtering of different protocols on the same port.
+.El
 .It Fl k
 Disable advertising of kernel release, version and machine. Kernel name
 (ie: Linux) will still be shared, and Inventory software version will be set
index 8a22b4eb9e11b16ff799ec4d313a092f0370de0a..9ad0efcf045b9582e4c7958d9197ac9a2cf13c42 100644 (file)
@@ -892,7 +892,7 @@ lldpd_update_localports(struct lldpd *cfg)
        };
        lldpd_ifhandlers *ifh;
 
-       log_debug("localports", "update information for local ports");
+       log_debug("localchassis", "update information for local ports");
 
        /* h_flags is set to 0 for each port. If the port is updated, h_flags
         * will be set to a non-zero value. This will allow us to clean up any
@@ -901,7 +901,7 @@ lldpd_update_localports(struct lldpd *cfg)
            hardware->h_flags = 0;
 
        if (getifaddrs(&ifap) != 0)
-               fatal("localports", "failed to get interface list");
+               fatal("localchassis", "failed to get interface list");
 
        /* We will run the list of interfaces through a list of interface
         * handlers. Each handler will create or update some hardware port (and
@@ -942,14 +942,14 @@ static void
 lldpd_exit(struct lldpd *cfg)
 {
        struct lldpd_hardware *hardware, *hardware_next;
-       log_debug("exit", "exit lldpd");
+       log_debug("main", "exit lldpd");
        close(cfg->g_ctl);
        priv_ctl_cleanup();
-       log_debug("exit", "cleanup hardware information");
+       log_debug("main", "cleanup hardware information");
        for (hardware = TAILQ_FIRST(&cfg->g_hardware); hardware != NULL;
             hardware = hardware_next) {
                hardware_next = TAILQ_NEXT(hardware, h_entries);
-               log_debug("exit", "cleanup interface %s", hardware->h_ifname);
+               log_debug("main", "cleanup interface %s", hardware->h_ifname);
                lldpd_remote_cleanup(hardware, NULL);
                lldpd_hardware_cleanup(cfg, hardware);
        }
@@ -1005,7 +1005,7 @@ lldpd_main(int argc, char *argv[])
        char *cidp = NULL;
        char *interfaces = NULL;
        char *popt, opts[] = 
-               "H:vhkrdxX:m:4:6:I:C:p:M:P:S:i@                    ";
+               "H:vhkrdD:xX:m:4:6:I:C:p:M:P:S:i@                    ";
        int i, found, advertise_version = 1;
 #ifdef ENABLE_LLDPMED
        int lldpmed = 0, noinventory = 0;
@@ -1044,6 +1044,9 @@ lldpd_main(int argc, char *argv[])
                case 'd':
                        debug++;
                        break;
+               case 'D':
+                       log_accept(optarg);
+                       break;
                case 'r':
                        receiveonly = 1;
                        break;
index 8257dd79125004610a2ec008637b25a4d931c8f1..bfb0b0992a530ffd94d7c326d5de9805812443ec 100644 (file)
@@ -2553,7 +2553,7 @@ _lldpctl_new_atom(lldpctl_conn_t *conn, atom_t type, ...)
                va_end(ap);
                return atom;
        }
-       log_warnx("atom", "unknown atom type: %d", type);
+       log_warnx("rpc", "unknown atom type: %d", type);
        SET_ERROR(conn, LLDPCTL_ERR_FATAL);
        return NULL;
 }
index 35a557c37b4c7b06d7ff9cb9d07509d561d35be3..daad84d5b9d9d8eea95428577580d285e6b86193 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -37,6 +37,9 @@ static void (*logh)(int severity, const char *msg) = NULL;
 static void     vlog(int, const char *, const char *, va_list);
 static void     logit(int, const char *, const char *, ...);
 
+#define MAX_DBG_TOKENS 40
+static const char const *tokens[MAX_DBG_TOKENS + 1] = {NULL};
+
 void
 log_init(int n_debug, const char *progname)
 {
@@ -54,6 +57,18 @@ log_register(void (*cb)(int, const char*))
        logh = cb;
 }
 
+void
+log_accept(const char *token)
+{
+       int i;
+       for (i = 0; i < MAX_DBG_TOKENS; i++) {
+               if (tokens[i] == NULL) {
+                       tokens[i+1] = NULL;
+                       tokens[i] = token;
+                       return;
+               }
+       }
+}
 
 static void
 logit(int pri, const char *token, const char *fmt, ...)
@@ -187,12 +202,26 @@ log_info(const char *token, const char *emsg, ...)
        }
 }
 
+static int
+log_debug_accept_token(const char *token)
+{
+       int i;
+       if (tokens[0] == NULL) return 1;
+       for (i = 0;
+            (i < MAX_DBG_TOKENS) && (tokens[i] != NULL);
+            i++) {
+               if (!strcmp(tokens[i], token))
+                       return 1;
+       }
+       return 0;
+}
+
 void
 log_debug(const char *token, const char *emsg, ...)
 {
        va_list  ap;
 
-       if (debug > 2 || logh) {
+       if ((debug > 2 && log_debug_accept_token(token)) || logh) {
                va_start(ap, emsg);
                vlog(LOG_DEBUG, token, emsg, ap);
                va_end(ap);
index 05a2b74833104e9212c94e26ba81f2675281594f..375d8ca05c564c5911ca3c3c28e120c13ef0dd82 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -28,5 +28,6 @@ void             fatal(const char*, const char *);
 void             fatalx(const char *);
 
 void            log_register(void (*cb)(int, const char*));
+void             log_accept(const char *);
 
 #endif