From: Vincent Bernat Date: Sun, 16 Dec 2012 14:58:14 +0000 (+0100) Subject: log: add -D option to filter out debug logs X-Git-Tag: 0.7.0~63 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e5d99d4ea52c41d3cf15006c319a5d0c14556ae;p=thirdparty%2Flldpd.git log: add -D option to filter out debug logs The list of accepted tokens is documented in the manual page. --- diff --git a/src/daemon/agent.c b/src/daemon/agent.c index 0c06a479..c33fea5e 100644 --- a/src/daemon/agent.c +++ b/src/daemon/agent.c @@ -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; diff --git a/src/daemon/interfaces.c b/src/daemon/interfaces.c index c8533c0e..7978d526 100644 --- a/src/daemon/interfaces.c +++ b/src/daemon/interfaces.c @@ -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, diff --git a/src/daemon/lldpd.8 b/src/daemon/lldpd.8 index ef97de63..5c7cd7ec 100644 --- a/src/daemon/lldpd.8 +++ b/src/daemon/lldpd.8 @@ -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 diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 8a22b4eb..9ad0efcf 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -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; diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index 8257dd79..bfb0b099 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -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; } diff --git a/src/log.c b/src/log.c index 35a557c3..daad84d5 100644 --- 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); diff --git a/src/log.h b/src/log.h index 05a2b748..375d8ca0 100644 --- 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