[MERGED] libosmocore[master]: logging: Extend log_target with call-back for un-formatted l...

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

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon Dec 5 18:48:36 UTC 2016


Harald Welte has submitted this change and it was merged.

Change subject: logging: Extend log_target with call-back for un-formatted log line
......................................................................


logging: Extend log_target with call-back for un-formatted log line

Some targets might not want to receive only an opaque, pre-formatted
string, but rather the unformatted arguments with metadata like
sub-system/level/file/line.  We solve this by introducing a
log_target->output_raw() function pointer.  If a target specifies this
function, it takes precedence over the regular log_target->output()
function.

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

Approvals:
  Max: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 3da9d33..581ebce 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -207,13 +207,29 @@
 	};
 
 	/*! \brief call-back function to be called when the logging framework
-	 *	   wants to log somethnig.
+	 *	   wants to log a fully formatted string
 	 *  \param[in] target logging target
 	 *  \param[in] level log level of currnet message
 	 *  \param[in] string the string that is to be written to the log
 	 */
         void (*output) (struct log_target *target, unsigned int level,
 			const char *string);
+
+	/*! \brief alternative call-back function to which the logging
+	 *	   framework passes the unfortmatted input arguments,
+	 *	   i.e. bypassing the internal string formatter
+	 *  \param[in] target logging target
+	 *  \param[in] subsys logging sub-system
+	 *  \param[in] level logging level
+	 *  \param[in] file soure code file name
+	 *  \param[in] line source code file line number
+	 *  \param[in] cont continuation of previous statement?
+	 *  \param[in] format format string
+	 *  \param[in] ap vararg list of printf arguments
+	 */
+	void (*raw_output)(struct log_target *target, int subsys,
+			   unsigned int level, const char *file, int line,
+			   int cont, const char *format, va_list ap);
 };
 
 /* use the above macros */
diff --git a/src/logging.c b/src/logging.c
index 9e30d5f..165d822 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -385,7 +385,10 @@
 		 * in undefined state. Since _output uses vsnprintf and it may
 		 * be called several times, we have to pass a copy of ap. */
 		va_copy(bp, ap);
-		_output(tar, subsys, level, file, line, cont, format, bp);
+		if (tar->raw_output)
+			tar->raw_output(tar, subsys, level, file, line, cont, format, bp);
+		else
+			_output(tar, subsys, level, file, line, cont, format, bp);
 		va_end(bp);
 	}
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9dc9205d70dce9581458e7e9dc2d8a92991897bd
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list