How can I get gSOAP to log into syslog?

82 views Asked by At

I'm using gSOAP on embedded Linux. I'm using Yocto so I added:

TARGET_CPPFLAGS += "-DDEBUG"

to the gsoap .bb recipe and that enabled logging. But what I get is three log files:

  • \RECV.log contains messages received, concatenated
  • \SENT.log contains messages sent, concatenated
  • \TEST.log contains debugging information to identify issues

What I'd like is for the logging from TEST.log to appear in syslog alongside my application so I can see what's happening in chronological order. Is there a standard way of doing this or am I going to have to modify the source code directly?

1

There are 1 answers

0
parsley72 On

There doesn't seem to be an existing way of doing this. I found this question log requests and responses but the plugin it mentions only saves the comms, not the logging.

So I've written my own patch. So far it's pretty basic but I'm including it here. It just prints all messages to syslog as LOG_NOTICE, although DBGHEX isn't implemented.

diff --git a/gsoap/stdsoap2.h b/gsoap/stdsoap2.h
index 9f6af794..5720768e 100644
--- a/gsoap/stdsoap2.h
+++ b/gsoap/stdsoap2.h
@@ -990,6 +990,10 @@ extern intmax_t __strtoull(const char*, char**, int);
 
 /* #define DEBUG_STAMP */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and time-stamped operations (in file TEST.log) */
 
+#ifdef DEBUG
+# include <syslog.h>
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -1933,7 +1937,8 @@ typedef unsigned short soap_ssl_flags;
 
 #ifdef SOAP_DEBUG
 # ifndef SOAP_MESSAGE
-#  define SOAP_MESSAGE fprintf
+  #  define SOAP_MESSAGE(USELESS_FDEBUG, ...) \
+     syslog(LOG_NOTICE, ##__VA_ARGS__);
 # endif
 # ifndef DBGLOG
 #  ifdef DEBUG_STAMP
@@ -1972,28 +1977,13 @@ typedef unsigned short soap_ssl_flags;
 #   endif
 #  else
 #   define DBGLOG(DBGFILE, CMD) \
-{ if (soap)\
-  { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\
-      soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\
-    if (soap->fdebug[SOAP_INDEX_##DBGFILE])\
-    { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\
-      CMD;\
-      fflush(fdebug);\
-    }\
-  }\
+{ CMD;\
 }
 #  endif
 # endif
 # ifndef DBGMSG
 #  define DBGMSG(DBGFILE, MSG, LEN) \
-{ if (soap)\
-  { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\
-      soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\
-    if (soap->fdebug[SOAP_INDEX_##DBGFILE])\
-    { fwrite((void*)(MSG), 1, (size_t)(LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\
-      fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\
-    }\
-  }\
+{ syslog(LOG_NOTICE, "%s", MSG); \
 }
 # endif
 # ifndef DBGFUN