Added debug-mode test of ignored return value
[asdcplib.git] / src / KM_log.cpp
index 985d2103289f9ea548e48f4110a006872aa0fda5..d820dba50df002aaf82e652c664d765e829dd386 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004-2009, John Hurst
+Copyright (c) 2004-2011, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -90,7 +90,8 @@ Kumu::DefaultLogSink()
 void
 Kumu::EntryListLogSink::WriteEntry(const LogEntry& Entry)
 {
-  AutoMutex L(m_Lock);
+  AutoMutex L(m_lock);
+  WriteEntryToListeners(Entry);
 
   if ( Entry.TestFilter(m_filter) )
     m_Target.push_back(Entry);
@@ -102,13 +103,15 @@ Kumu::EntryListLogSink::WriteEntry(const LogEntry& Entry)
 void
 Kumu::StdioLogSink::WriteEntry(const LogEntry& Entry)
 {
-  AutoMutex L(m_Lock);
   std::string buf;
+  AutoMutex L(m_lock);
+  WriteEntryToListeners(Entry);
 
   if ( Entry.TestFilter(m_filter) )
     {
       Entry.CreateStringWithOptions(buf, m_options);
       fputs(buf.c_str(), m_stream);
+      fflush(m_stream);
     }
 }
 
@@ -116,16 +119,19 @@ Kumu::StdioLogSink::WriteEntry(const LogEntry& Entry)
 
 #ifdef KM_WIN32
 //
+// http://www.codeguru.com/forum/showthread.php?t=231165
+//
 void
 Kumu::WinDbgLogSink::WriteEntry(const LogEntry& Entry)
 {
-  AutoMutex L(m_Lock);
   std::string buf;
+  AutoMutex L(m_lock);
+  WriteEntryToListeners(Entry);
 
   if ( Entry.TestFilter(m_filter) )
     {
       Entry.CreateStringWithOptions(buf, m_options);
-      ::OutputDebugString(buf.c_str());
+      ::OutputDebugStringA(buf.c_str());
     }
 }
 #endif
@@ -138,13 +144,15 @@ Kumu::WinDbgLogSink::WriteEntry(const LogEntry& Entry)
 void
 Kumu::StreamLogSink::WriteEntry(const LogEntry& Entry)
 {
-  AutoMutex L(m_Lock);
   std::string buf;
+  AutoMutex L(m_lock);
+  WriteEntryToListeners(Entry);
 
   if ( Entry.TestFilter(m_filter) )
     {
       Entry.CreateStringWithOptions(buf, m_options);
-      write(m_fd, buf.c_str(), buf.size());
+      ssize_t n = write(m_fd, buf.c_str(), buf.size());
+      assert(n==buf.size());
     }
 }
 
@@ -170,7 +178,7 @@ int const SYSLOG_DEBUG = LOG_DEBUG;
 Kumu::SyslogLogSink::SyslogLogSink(const std::string& source_name, int facility)
 {
   if ( facility == 0 )
-    facility == LOG_DAEMON;
+    facility = LOG_DAEMON;
 
   openlog(source_name.c_str(), LOG_CONS|LOG_NDELAY||LOG_PID, facility);
 }
@@ -197,7 +205,8 @@ Kumu::SyslogLogSink::WriteEntry(const LogEntry& Entry)
     case Kumu::LOG_DEBUG:   priority = SYSLOG_DEBUG; break;
     }
 
-  AutoMutex L(m_Lock);
+  AutoMutex L(m_lock);
+  WriteEntryToListeners(Entry);
 
   if ( Entry.TestFilter(m_filter) )
     {