]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lib: enable ability to change log level on-the-fly
authorVincent Bernat <vincent@bernat.im>
Sat, 16 May 2015 06:05:24 +0000 (08:05 +0200)
committerVincent Bernat <vincent@bernat.im>
Sat, 16 May 2015 06:05:24 +0000 (08:05 +0200)
And remove the previous commit, use internal logging instead.

src/client/lldpcli.c
src/lib/Makefile.am
src/lib/errors.c
src/lib/lldpctl.h
src/log.c
src/log.h

index 98d4267fed1a046abb56c21df100b595510b2961..fc97c612ac55795987a54c77a53d527189115789 100644 (file)
@@ -31,7 +31,6 @@
 #include <dirent.h>
 #include <signal.h>
 #include <sys/queue.h>
-#include <syslog.h>
 
 #include "client.h"
 
@@ -45,18 +44,6 @@ extern const char    *__progname;
 static struct cmd_node *root = NULL;
 const char *ctlname = NULL;
 
-static void
-log_from_lib(int severity, const char *msg)
-{
-       switch (severity) {
-       case LOG_DEBUG: log_debug("liblldpctl", "%s", msg); break;
-       case LOG_INFO:
-       case LOG_NOTICE: log_info("liblldpctl", "%s", msg); break;
-       default:
-               log_warnx("liblldpctl", "%s", msg); break;
-       }
-}
-
 static int
 is_lldpctl(const char *name)
 {
@@ -463,6 +450,7 @@ main(int argc, char *argv[])
                }
        }
        log_init(debug, __progname);
+       lldpctl_log_level(debug);
 
        /* Get and parse command line options */
        optind = 1;
@@ -498,9 +486,6 @@ main(int argc, char *argv[])
        /* Register commands */
        root = register_commands();
 
-       /* Initialize logging for liblldpctl */
-       lldpctl_log_callback(log_from_lib);
-
        /* Make a connection */
        log_debug("lldpctl", "connect to lldpd");
        conn = lldpctl_new_name(ctlname, NULL, NULL, NULL);
index 1cc798058a241a2052c6663f59425938576ed220..a7709bf15a04d58f9eae9f47982de0d575f62d1f 100644 (file)
@@ -13,7 +13,7 @@ liblldpctl_la_SOURCES = \
        atoms/config.c atoms/dot1.c atoms/dot3.c \
        atoms/interface.c atoms/med.c atoms/mgmt.c atoms/port.c
 liblldpctl_la_LIBADD  = $(top_builddir)/src/libcommon-daemon-lib.la libfixedpoint.la
-liblldpctl_la_LDFLAGS = $(AM_LDFLAGS) -export-symbols-regex '^lldpctl_' -version-info 9:0:5
+liblldpctl_la_LDFLAGS = $(AM_LDFLAGS) -export-symbols-regex '^lldpctl_' -version-info 10:0:6
 
 # -version-info format is `current`:`revision`:`age`. For more details, see:
 #   http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91
index 33860b1b6e66dd8453571f5d923b7348d52fef7a..0bd31f325c490bb3d4e8b527abd142608d1bb0b8 100644 (file)
@@ -53,3 +53,9 @@ lldpctl_log_callback(void (*cb)(int severity, const char *msg))
 {
        log_register(cb);
 }
+
+void
+lldpctl_log_level(int level)
+{
+       log_level(level);
+}
index 9f1542338850f621a8865302fed055d17ab9f132..3f07e442b2a484ce43bc69270e7f1b2e70a494d8 100644 (file)
@@ -256,6 +256,17 @@ int lldpctl_release(lldpctl_conn_t *conn);
  */
 void lldpctl_log_callback(void (*cb)(int severity, const char *msg));
 
+/**
+ * Setup log level.
+ *
+ * By default, liblldpctl will only log warnings. The following function allows
+ * to increase verbosity. This function has no effect if callbacks are
+ * registered with the previous function.
+ *
+ * @param level    Level of verbosity (1 = warnings, 2 = info, 3 = debug).
+ */
+void lldpctl_log_level(int level);
+
 /**
  * Possible error codes for functions that return negative integers on
  * this purpose or for @c lldpctl_last_error().
index 4f266bfcf93243df10a5187bc82c65480477f6b6..d1106fa8d34fd219048dbacb4b08500098cdb7dc 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -50,6 +50,13 @@ log_init(int n_debug, const char *progname)
        tzset();
 }
 
+void
+log_level(int n_debug)
+{
+       if (debug > 0 && n_debug >= 1)
+               debug = n_debug;
+}
+
 void
 log_register(void (*cb)(int, const char*))
 {
index df9858579358931ce2eb7fac07afdbd51eb73ec3..9f8707ed8e25d5c279950cc89b2daddeedd659eb 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -29,5 +29,6 @@ void             fatalx(const char *, const char *) __attribute__((__noreturn__)
 
 void            log_register(void (*cb)(int, const char*));
 void             log_accept(const char *);
+void            log_level(int);
 
 #endif