[PATCH] Added ForceLogVA


Ian Bell <IBell@...>
 

From ed97cb006a85e33aa892996791f7ac7795506336 Mon Sep 17 00:00:00 2001

Message-Id: <ed97cb006a85e33aa892996791f7ac7795506336.1348585382.git.ibell@...>

From: Ian Bell <ibell@...>

Date: Tue, 25 Sep 2012 14:02:25 +0100

Subject: [PATCH] Added ForceLogVA

 

Added a new API to allow forced logging using a va args.

Also adding a missing thread id log statment.

 

Signed-off-by: Ian Bell <ibell@...>

---

mama/c_cpp/src/c/log.c      |   37 ++++++++++++++++++++++++++++++++-----

mama/c_cpp/src/c/mama/log.h |    6 +++++-

2 files changed, 37 insertions(+), 6 deletions(-)

 

diff --git a/mama/c_cpp/src/c/log.c b/mama/c_cpp/src/c/log.c

index d19a7fe..b8ed3dd 100644

--- a/mama/c_cpp/src/c/log.c

+++ b/mama/c_cpp/src/c/log.c

@@ -562,6 +562,7 @@ mama_forceLogDefault (MamaLogLevel level,

                               mamaLog_getTime(ts, MAMALOG_TIME_BUFFER_LENGTH);

                                fprintf (f, "%s", ts);

+        fprintf (f, "(%x) : ", (unsigned int)wGetCurrentThreadId());

                               vfprintf (f, format, ap);

                               fprintf (f, "\n");

                               fflush (f);

@@ -1037,6 +1038,29 @@ mama_logVa(MamaLogLevel level,

}

 void

+mama_forceLogVa(const char   *format,

+           va_list      args)

+{

+             /* Get the log function and the log level under the reader lock. */

+             MamaLogLevel currentLevel       = 0;

+             mamaLogCb       logFunction       = NULL;

+

+             /* Acquire the read lock. */

+             mamaLog_acquireLock(1);

+

+             /* Get the variables. */

+             currentLevel      = gMamaLogLevel;

+             logFunction = gMamaForceLogFunc;

+            

+             /* Release the read lock as quickly as possible. */

+             MRSWLock_release(g_lock, 1);

+

+             /* Call the log function. */

+    logFunction(currentLevel, format, args);

+}

+

+

+void

mama_forceLog (MamaLogLevel level, const char *format, ...)

{

               /* Get the log function under the reader lock. */

@@ -1148,7 +1172,8 @@ mama_tryStringToLogLevel(const char*   s,

     {

         *level=MAMA_LOG_LEVEL_ERROR;

     }

-    else if (0==strcasecmp(s,"Warn"))

+    else if (0==strcasecmp(s,"Warn")

+             || 0==strcasecmp(s, "Warning"))

     {

         *level=MAMA_LOG_LEVEL_WARN;

     }

@@ -1160,11 +1185,13 @@ mama_tryStringToLogLevel(const char*   s,

     {

         *level=MAMA_LOG_LEVEL_FINE;

     }

-    else if (0==strcasecmp(s,"Finer"))

+    else if (0==strcasecmp(s,"Finer")

+             || 0==strcasecmp(s, "Verbose"))

     {

         *level=MAMA_LOG_LEVEL_FINER;

     }

-    else if (0==strcasecmp(s,"Finest"))

+    else if (0==strcasecmp(s,"Finest")

+             || 0==strcasecmp(s, "Debug"))

     {

         *level=MAMA_LOG_LEVEL_FINEST;

     }

@@ -1223,7 +1250,7 @@ int mama_logDecrementVerbosity(MamaLogLevel* level)

     return 1;

}

-mama_status mama_logForceRollLogFiles()

+mama_status mama_logForceRollLogFiles(void)

{

     mama_status ret = MAMA_STATUS_INVALID_ARG;

     MRSW_RESULT            al = mamaLog_acquireLock(0);

@@ -1231,7 +1258,7 @@ mama_status mama_logForceRollLogFiles()

               {

         ret = mamaLog_rollLogFiles();

                               /* Release the read lock. */

-                              MRSWLock_release(g_lock, 1);

+                             MRSWLock_release(g_lock, 0);

               }

     return ret;

}

diff --git a/mama/c_cpp/src/c/mama/log.h b/mama/c_cpp/src/c/mama/log.h

index 239eaaf..b988a6c 100644

--- a/mama/c_cpp/src/c/mama/log.h

+++ b/mama/c_cpp/src/c/mama/log.h

@@ -141,6 +141,10 @@ MAMAExpDLL

extern void

mama_logVa (MamaLogLevel level, const char *format, va_list args);

+/** Used  for the force logging using variable argument parameters*/

+MAMAExpDLL

+extern void

+mama_forceLogVa(const char   *format, va_list  args);

MAMAExpDLL

extern void

mama_forceLog (MamaLogLevel level, const char *format, ...);

@@ -289,7 +293,7 @@ mama_logDecrementVerbosity(MamaLogLevel* level);

  */

MAMAExpDLL

extern mama_status

-mama_logForceRollLogFiles();

+mama_logForceRollLogFiles(void);

 /**  Destroy memory held by the logging */

void

--

1.7.9.5

 




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.