This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH setup 1/4] Add Log adaptors for printf-style output


---
 ChangeLog       |  5 +++++
 LogSingleton.cc | 28 ++++++++++++++++++++++++++++
 LogSingleton.h  |  5 +++++
 3 files changed, 38 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 551cc94..0822701 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-04  Jon TURNEY  <jon.turney@dronecode.org.uk>
+
+	* LogSingleton.cc (LogBabblePrintf, LogPlainPrintf): Add.
+	* LogSingleton.h: Ditto.
+
 2015-03-02  Jon TURNEY  <jon.turney@dronecode.org.uk>
 
 	* LogFile.cc (endEntry): Remove msg().
diff --git a/LogSingleton.cc b/LogSingleton.cc
index 387e6fe..a103a20 100644
--- a/LogSingleton.cc
+++ b/LogSingleton.cc
@@ -15,6 +15,7 @@
 
 #include "LogSingleton.h"
 #include <stdexcept>
+#include <stdarg.h>
 
 using namespace std;
 
@@ -76,3 +77,30 @@ private:
   static LogSingleton *theInstance;
 };
 #endif
+
+// Log adapators for printf-style output
+void
+LogBabblePrintf(const char *fmt, ...)
+{
+  int len;
+  char buf[2000];
+  va_list args;
+  va_start (args, fmt);
+  len = vsnprintf (buf, 2000, fmt, args);
+  if ((len > 0) && (buf[len-1] == '\n'))
+    buf[len-1] = 0;
+  Log (LOG_BABBLE) << buf << endLog;
+}
+
+void
+LogPlainPrintf(const char *fmt, ...)
+{
+  int len;
+  char buf[2000];
+  va_list args;
+  va_start (args, fmt);
+  len = vsnprintf (buf, 2000, fmt, args);
+  if ((len > 0) && (buf[len-1] == '\n'))
+    buf[len-1] = 0;
+  Log (LOG_PLAIN) << buf << endLog;
+}
diff --git a/LogSingleton.h b/LogSingleton.h
index 2c7a7c5..2fd1e36 100644
--- a/LogSingleton.h
+++ b/LogSingleton.h
@@ -57,4 +57,9 @@ extern std::ostream& endLog(std::ostream& outs);
 //extern ostream& endLog(ostream& outs);
 
 #define Log(X) (LogSingleton::GetInstance ()(X))
+
+// Log adapators for printf-style output
+void LogBabblePrintf(const char *fmt, ...);
+void LogPlainPrintf(const char *fmt, ...);
+
 #endif /* SETUP_LOGSINGLETON_H */
-- 
2.1.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]