Change in libosmocore[master]: add LOGPFSMSL(), LOGPFSMSLSRC()

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
Wed Dec 19 23:23:15 UTC 2018


Neels Hofmeyr has uploaded this change for review. ( https://gerrit.osmocom.org/12386


Change subject: add LOGPFSMSL(), LOGPFSMSLSRC()
......................................................................

add LOGPFSMSL(), LOGPFSMSLSRC()

Using an FSM instace's logging context is very useful. Sometimes it makes sense
to log something on a different logging category than the FSM definition's
default category.

For example, an MSC conn has aspects concerning MM, CC, RR, MGCP, ..., and
currently all of those log on DMM.

This came up in I358cfbaf0f44f25148e8b9bafcb9257b1952b35a, where I want to log
an MGCP event using a ran_conn context, and used the conn->fi->id. That of
course omits context like the current conn FSM state...

I remember at least one other place where I recently added logging using some
fi->id as context, so it might turn out useful in various places.

Change-Id: I11b182a03f5ecb6df7cd8f260757d3626c8e945d
---
M include/osmocom/core/fsm.h
1 file changed, 30 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/86/12386/1

diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h
index 5b43e56..3c35c20 100644
--- a/include/osmocom/core/fsm.h
+++ b/include/osmocom/core/fsm.h
@@ -119,6 +119,34 @@
 
 void osmo_fsm_log_addr(bool log_addr);
 
+/*! Log using FSM instance's context, on explicit logging subsystem and level.
+ * \param fi  An osmo_fsm_inst.
+ * \param subsys  A logging subsystem, e.g. DLGLOBAL.
+ * \param level  A logging level, e.g. LOGL_INFO.
+ * \param fmt  printf-like string format.
+ * \param args  String format arguments.
+ */
+#define LOGPFSMSL(fi, subsys, level, fmt, args...) \
+		LOGPFSMSLSRC(fi, subsys, level, __FILE__, __LINE__, fmt, ## args)
+
+/*! Log using FSM instance's context, on explicit logging subsystem and level,
+ * and passing explicit source file and line information.
+ * \param fi  An osmo_fsm_inst.
+ * \param subsys  A logging subsystem, e.g. DLGLOBAL.
+ * \param level  A logging level, e.g. LOGL_INFO.
+ * \param caller_file  A string constant containing a source file path, like __FILE__.
+ * \param caller_line  A number constant containing a source file line, like __LINE__.
+ * \param fmt  printf-like string format.
+ * \param args  String format arguments.
+ */
+#define LOGPFSMSLSRC(fi, subsys, level, caller_file, caller_line, fmt, args...) \
+		LOGPSRC(subsys, level, \
+			caller_file, caller_line, \
+			"%s{%s}: " fmt, \
+			osmo_fsm_inst_name(fi), \
+			(fi) ? osmo_fsm_state_name((fi)->fsm, (fi)->state) : "fi=NULL", ## args)
+
+
 /*! Log using FSM instance's context, on explicit logging level.
  * \param fi  An osmo_fsm_inst.
  * \param level  A logging level, e.g. LOGL_INFO.
@@ -138,12 +166,8 @@
  * \param args  String format arguments.
  */
 #define LOGPFSMLSRC(fi, level, caller_file, caller_line, fmt, args...) \
-		LOGPSRC((fi) ? (fi)->fsm->log_subsys : DLGLOBAL, level, \
-			caller_file, caller_line, \
-			"%s{%s}: " fmt, \
-			osmo_fsm_inst_name(fi), \
-			(fi) ? osmo_fsm_state_name((fi)->fsm, (fi)->state) : "fi=NULL", \
-			## args)
+		LOGPFSMSLSRC(fi, (fi) ? (fi)->fsm->log_subsys : DLGLOBAL, level, \
+			     caller_file, caller_line, fmt, ## args)
 
 /*! Log using FSM instance's context.
  * The log level to log on is obtained from the FSM instance.

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I11b182a03f5ecb6df7cd8f260757d3626c8e945d
Gerrit-Change-Number: 12386
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181219/981902a0/attachment.htm>


More information about the gerrit-log mailing list