release candidate
[asdcplib.git] / src / KM_log.h
index 6da77df4627ff1e5c5646fc48333b1132cb8ef4f..09897060386752eb98e12e6190ff77be5f230f06 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2004-2007, John Hurst
+Copyright (c) 2004-2009, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -38,6 +38,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <KM_util.h>
 #include <stdarg.h>
 #include <errno.h>
+#include <iosfwd>
 
 #define LOG_MSG_IMPL(t) \
   va_list args; \
@@ -101,8 +102,7 @@ namespace Kumu
   const i32_t LOG_ALLOW_NONE       = 0x00000000;
   const i32_t LOG_ALLOW_ALL        = 0x000fffff;
 
-  // options are used to control display format
-  // default is 0 (
+  // options are used to control display format default is 0.
   const i32_t LOG_OPTION_TYPE      = 0x01000000;
   const i32_t LOG_OPTION_TIMESTAMP = 0x02000000;
   const i32_t LOG_OPTION_PID       = 0x04000000;
@@ -136,8 +136,12 @@ namespace Kumu
     bool   Unarchive(MemIOReader* Reader);
   };
 
+  //
+  std::basic_ostream<char, std::char_traits<char> >&
+    operator<<(std::basic_ostream<char, std::char_traits<char> >& strm, LogEntry const& Entry);
+
 
-  typedef ArchivableList<LogEntry> LogEntryList_t;
+  typedef ArchivableList<LogEntry> LogEntryList;
   
   //
   class ILogSink
@@ -231,12 +235,12 @@ namespace Kumu
   class EntryListLogSink : public ILogSink
   {
     Mutex m_Lock;
-    LogEntryList_t& m_Target;
+    LogEntryList& m_Target;
     KM_NO_COPY_CONSTRUCT(EntryListLogSink);
     EntryListLogSink();
 
   public:
-    EntryListLogSink(LogEntryList_t& target) : m_Target(target) {}
+    EntryListLogSink(LogEntryList& target) : m_Target(target) {}
     virtual ~EntryListLogSink() {}
 
     void WriteEntry(const LogEntry& Entry);
@@ -288,6 +292,23 @@ namespace Kumu
 
       void WriteEntry(const LogEntry&);
     };
+
+  // write messages to the syslog facility
+  class SyslogLogSink : public ILogSink
+    {
+      Mutex m_Lock;
+      KM_NO_COPY_CONSTRUCT(SyslogLogSink);
+      SyslogLogSink();
+  
+    public:
+      SyslogLogSink(const std::string& source_name, int facility);
+      virtual ~SyslogLogSink();
+      void WriteEntry(const LogEntry&);
+    };
+
+  // convert a string into the appropriate syslog facility id
+  int SyslogNameToFacility(const std::string& facility_name);
+
 #endif