[PATCH] libosmocore[master]: vty: fix "everything" logging option

Max gerrit-no-reply at lists.osmocom.org
Fri Feb 17 15:46:29 UTC 2017


Hello Harald Welte, Jenkins Builder, Holger Freyther,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1582

to look at the new patch set (#6).

vty: fix "everything" logging option

* clarify use of unused parameters
* change internal static function int check_log_to_target() to more
  appropriate bool should_log_to_target()
* add explicit level for "logging level ... everything" so it really
  logs everything instead of nothing for a given category
* fix "logging level all everything" with explicit global loglevel check

Fixes: OS#71
Change-Id: Ib51987fb2f64a70fca130f3799dc8fd71cc7085c
---
M include/osmocom/core/logging.h
M include/osmocom/vty/logging.h
M src/logging.c
M src/vty/logging_vty.c
M tests/vty/vty_test.c
5 files changed, 29 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/82/1582/6

diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index fcf77f0..aef145d 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -88,6 +88,8 @@
 #define LOGL_NOTICE	5	/*!< \brief abnormal/unexpected condition */
 #define LOGL_ERROR	7	/*!< \brief error condition, requires user action */
 #define LOGL_FATAL	8	/*!< \brief fatal, program aborted */
+/* N. B: check that you do not clash with internal LOGL_EVERY from logging.c
+   before adding anything to above */
 
 #define LOG_FILTER_ALL	0x0001
 
@@ -299,8 +301,8 @@
 void log_del_target(struct log_target *target);
 
 /* Generate command string for VTY use */
-const char *log_vty_command_string(const struct log_info *info);
-const char *log_vty_command_description(const struct log_info *info);
+const char *log_vty_command_string(const struct log_info *unused_info);
+const char *log_vty_command_description(const struct log_info *unused_info);
 
 struct log_target *log_target_find(int type, const char *fname);
 extern struct llist_head osmo_log_target_list;
diff --git a/include/osmocom/vty/logging.h b/include/osmocom/vty/logging.h
index 9e4b98f..544d117 100644
--- a/include/osmocom/vty/logging.h
+++ b/include/osmocom/vty/logging.h
@@ -4,6 +4,6 @@
 #define FILTER_STR	"Filter log messages\n"
 
 struct log_info;
-void logging_vty_add_cmds(const struct log_info *cat);
+void logging_vty_add_cmds();
 struct vty;
 struct log_target *osmo_log_vty2tgt(struct vty *vty);
diff --git a/src/logging.c b/src/logging.c
index 9b7d6f4..d170bfa 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -55,9 +55,10 @@
 LLIST_HEAD(osmo_log_target_list);
 
 #define LOGLEVEL_DEFS	6	/* Number of loglevels.*/
+#define LOGL_EVERY	32	/* Special loglevel for "everything". */
 
 static const struct value_string loglevel_strs[LOGLEVEL_DEFS+1] = {
-	{ 0,		"EVERYTHING" },
+	{ LOGL_EVERY,	"EVERYTHING" },
 	{ LOGL_DEBUG,	"DEBUG" },
 	{ LOGL_INFO,	"INFO" },
 	{ LOGL_NOTICE,	"NOTICE" },
@@ -138,7 +139,7 @@
 /*! \brief descriptive string for each log level */
 /* You have to keep this in sync with the structure loglevel_strs. */
 const char *loglevel_descriptions[LOGLEVEL_DEFS+1] = {
-	"Don't use. It doesn't log anything",
+	"Log everything (use with extreme care)",
 	"Log debug messages and higher levels",
 	"Log informational messages and higher levels",
 	"Log noticeable messages and higher levels",
@@ -352,36 +353,45 @@
 	return subsys;
 }
 
-static inline int check_log_to_target(struct log_target *tar, int subsys, int level)
+static inline bool should_log_to_target(struct log_target *tar, int subsys,
+					int level)
 {
 	struct log_category *category;
 
 	category = &tar->categories[subsys];
 
+	/* Check if special log level "everything" is enabled globally */
+	if (tar->loglevel == LOGL_EVERY)
+		return true;
+
 	/* subsystem is not supposed to be logged */
 	if (!category->enabled)
-		return 0;
+		return false;
 
 	/* Check the global log level */
 	if (tar->loglevel != 0 && level < tar->loglevel)
-		return 0;
+		return true;
+
+	/* Check if special log level "everything" is enabled for category */
+	if (category->loglevel == LOGL_EVERY)
+		return true;
 
 	/* Check the category log level */
 	if (tar->loglevel == 0 && category->loglevel != 0 &&
 	    level < category->loglevel)
-		return 0;
+		return false;
 
 	/* Apply filters here... if that becomes messy we will
 	 * need to put filters in a list and each filter will
 	 * say stop, continue, output */
 	if ((tar->filter_map & LOG_FILTER_ALL) != 0)
-		return 1;
+		return true;
 
 	if (osmo_log_info->filter_fn)
 		return osmo_log_info->filter_fn(&log_context, tar);
 
 	/* TODO: Check the filter/selector too? */
-	return 1;
+	return true;
 }
 
 /*! \brief vararg version of logging function
@@ -402,7 +412,7 @@
 	llist_for_each_entry(tar, &osmo_log_target_list, entry) {
 		va_list bp;
 
-		if (!check_log_to_target(tar, subsys, level))
+		if (!should_log_to_target(tar, subsys, level))
 			continue;
 
 		/* According to the manpage, vsnprintf leaves the value of ap
@@ -978,7 +988,7 @@
 	/* TODO: The following could/should be cached (update on config) */
 
 	llist_for_each_entry(tar, &osmo_log_target_list, entry) {
-		if (!check_log_to_target(tar, subsys, level))
+		if (!should_log_to_target(tar, subsys, level))
 			continue;
 
 		/* This might get logged (ignoring filters) */
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c
index 6004c47..b3674fb 100644
--- a/src/vty/logging_vty.c
+++ b/src/vty/logging_vty.c
@@ -737,7 +737,7 @@
 	return 1;
 }
 
-void logging_vty_add_cmds(const struct log_info *cat)
+void logging_vty_add_cmds()
 {
 	install_element_ve(&enable_logging_cmd);
 	install_element_ve(&disable_logging_cmd);
@@ -750,8 +750,8 @@
 	install_element_ve(&logging_set_category_mask_old_cmd);
 
 	/* Logging level strings are generated dynamically. */
-	logging_level_cmd.string = log_vty_command_string(cat);
-	logging_level_cmd.doc = log_vty_command_description(cat);
+	logging_level_cmd.string = log_vty_command_string(NULL);
+	logging_level_cmd.doc = log_vty_command_description(NULL);
 	install_element_ve(&logging_level_cmd);
 	install_element_ve(&show_logging_vty_cmd);
 	install_element_ve(&show_alarms_cmd);
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index 865c93e..1e1b495 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -318,7 +318,7 @@
 	vty_init(&vty_info);
 
 	/* Setup VTY commands */
-	logging_vty_add_cmds(&log_info);
+	logging_vty_add_cmds();
 	osmo_stats_vty_add_cmds();
 
 	test_cmd_string_from_valstr();

-- 
To view, visit https://gerrit.osmocom.org/1582
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ib51987fb2f64a70fca130f3799dc8fd71cc7085c
Gerrit-PatchSet: 6
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>


More information about the gerrit-log mailing list