[PATCH] libosmocore[master]: logging: separate the '<000b>' subsys from filename logging

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/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Jan 16 02:34:08 UTC 2018


Review at  https://gerrit.osmocom.org/5812

logging: separate the '<000b>' subsys from filename logging

Allow to log only the source filename and omit the (weird) hex output of the
logging subsystem.

The default behavior and old API usage remains unchanged.

To remain backwards compatible:
- Add a new flag to the end of struct log_target.
- Interpret the log_set_print_filename(tgt, 1) as the legacy behavior of
  printing the category along.

Print without the hex-category when log_set_print_filename() is called with 2
as parameter instead of 1. Document this in API doc.

A VTY command is following in a subsequent patch.

Change-Id: Iba03a2b7915853c6dccaf6c393c31405320538b4
---
M include/osmocom/core/logging.h
M src/logging.c
2 files changed, 22 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/12/5812/1

diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 1e809d0..149ef82 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -301,6 +301,8 @@
 
 	/* Should the log level be printed? */
 	bool print_level;
+	/* With filename output, should the subsys be printed as hex like '<000b>'? */
+	bool print_filename_subsys_hex;
 };
 
 /* use the above macros */
diff --git a/src/logging.c b/src/logging.c
index a6aa7eb..254afeb 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -385,9 +385,14 @@
 				goto err;
 			OSMO_SNPRINTF_RET(ret, rem, offset, len);
 		}
+		if (target->print_filename && target->print_filename_subsys_hex) {
+			ret = snprintf(buf + offset, rem, "<%4.4x> ", subsys);
+			if (ret < 0)
+				goto err;
+			OSMO_SNPRINTF_RET(ret, rem, offset, len);
+		}
 		if (target->print_filename) {
-			ret = snprintf(buf + offset, rem, "<%4.4x> %s:%d ",
-					subsys, file, line);
+			ret = snprintf(buf + offset, rem, "%s:%d ", file, line);
 			if (ret < 0)
 				goto err;
 			OSMO_SNPRINTF_RET(ret, rem, offset, len);
@@ -620,13 +625,22 @@
 	target->print_ext_timestamp = print_timestamp;
 }
 
-/*! Enable or disable printing of the filename while logging
+/*! Enable or disable printing of the filename while logging.
+ * Note, legacy behavior is to always log the subsystem (a.k.a. category) as
+ * '<000b>' hex representation along with the filename. Passing 1 as value
+ * enables this legacy behavior, as backwards compatible API. Passing 2 as
+ * value enables filenames, but omits the hex representation of the subsystem.
+ * Note that log_set_print_category() logs a human readable representation of
+ * the subsystem, independently from the source filename.
  *  \param[in] target Log target to be affected
- *  \param[in] print_filename Enable (1) or disable (0) filenames
+ *  \param[in] print_filename Enable (1) or disable (0) filenames,
+ *                            or 2 to enable filenames and omit the
+ *                            subsystem in hex representation.
  */
 void log_set_print_filename(struct log_target *target, int print_filename)
 {
-	target->print_filename = print_filename;
+	target->print_filename = print_filename ? 1 : 0;
+	target->print_filename_subsys_hex = (print_filename == 2)? false : true;
 }
 
 /*! Enable or disable printing of the category name
@@ -723,6 +737,7 @@
 	target->use_color = 1;
 	target->print_timestamp = 0;
 	target->print_filename = 1;
+	target->print_filename_subsys_hex = true;
 
 	/* global log level */
 	target->loglevel = 0;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba03a2b7915853c6dccaf6c393c31405320538b4
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list