Change in libosmocore[master]: logging.c: Add valuestrings for loglevels

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

dexter gerrit-no-reply at lists.osmocom.org
Mon Jan 13 12:48:10 UTC 2020


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/16832 )


Change subject: logging.c: Add valuestrings for loglevels
......................................................................

logging.c: Add valuestrings for loglevels

It might be helpful to convert a loglevel into a value string, lets add
a function for this.

Related: OS#2577
Change-Id: I81e58dbae9889f1424ff107a22ed0e838bea7f5b
---
M include/osmocom/core/logging.h
M src/logging.c
2 files changed, 16 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/32/16832/1

diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 79eec10..2d9dace 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -10,6 +10,8 @@
 #include <stdbool.h>
 #include <osmocom/core/defs.h>
 #include <osmocom/core/linuxlist.h>
+#include <osmocom/core/utils.h>
+
 
 /*! Maximum number of logging contexts */
 #define LOG_MAX_CTX		8
@@ -105,6 +107,11 @@
 #define LOGL_ERROR	7	/*!< error condition, requires user action */
 #define LOGL_FATAL	8	/*!< fatal, program aborted */
 
+extern const struct value_string log_level_names[];
+static inline const char *log_level_name(uint8_t val) {
+	return get_value_string(log_level_names, val);
+}
+
 /* logging subsystems defined by the library itself */
 #define DLGLOBAL	-1	/*!< global logging */
 #define DLLAPD		-2	/*!< LAPD implementation */
diff --git a/src/logging.c b/src/logging.c
index 4d6224d..a871cad 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -64,6 +64,15 @@
 void *tall_log_ctx = NULL;
 LLIST_HEAD(osmo_log_target_list);
 
+const struct value_string log_level_names[] = {
+	{ LOGL_DEBUG, 		"LOGL_DEBUG" },
+	{ LOGL_INFO, 		"LOGL_INFO" },
+	{ LOGL_NOTICE, 		"LOGL_NOTICE" },
+	{ LOGL_ERROR, 		"LOGL_ERROR" },
+	{ LOGL_FATAL, 		"LOGL_FATAL" },
+	{ 0, NULL }
+};
+
 #if (!EMBEDDED)
 /*! This mutex must be held while using osmo_log_target_list or any of its
   log_targets in a multithread program. Prevents race conditions between threads

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16832
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I81e58dbae9889f1424ff107a22ed0e838bea7f5b
Gerrit-Change-Number: 16832
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200113/7b1c8838/attachment.htm>


More information about the gerrit-log mailing list