dexter has uploaded this change for review. ( )

Change subject: logging: use LOGL_NOTICE when not loglevel is set

logging: use LOGL_NOTICE when not loglevel is set

when the API user of libosmocores logging infrastructure does not set a
pre-defined logging level in struct log_info_cat, the result would be an
invalid logging level. In order to avoid problems with that and to spare
all the additional .loglevel = LOGL_NOTICE (API users are advised to use
LOGL_NOTICE as default) lines in the user code lets check the logging
level on startup and set LOGL_NOTICE if there is no logging level set.

Change-Id: Ib9e180261505062505fc4605a98023910f76cde6
Related: OS#2577
M src/logging.c
1 file changed, 8 insertions(+), 1 deletion(-)

  git pull ssh:// refs/changes/04/17604/1

diff --git a/src/logging.c b/src/logging.c
index 4d6224d..d67181c 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -1052,10 +1052,17 @@
                return -ENOMEM;
-       if (inf) { /* copy over the user part */
+       /* copy over the user part and sanitize loglevel */
+       if (inf) {
                for (i = 0; i < inf->num_cat; i++) {
                        memcpy((struct log_info_cat *) &osmo_log_info->cat[i],
                               &inf->cat[i], sizeof(struct log_info_cat));
+                       /* Make sure that the loglevel is set to NOTICE in case
+                        * no loglevel has been preset. */
+                       if (!osmo_log_info->cat[i].loglevel)
+                               *(uint8_t*) (&osmo_log_info->cat[i].loglevel) =
+                                   LOGL_NOTICE;

To view, visit
To unsubscribe, or for help writing mail filters, visit

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ib9e180261505062505fc4605a98023910f76cde6
Gerrit-Change-Number: 17604
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <>
Gerrit-MessageType: newchange

Reply via email to