wutil_log.h

00001 // wutil_log.h
00002 //
00003 // CLog interface - Provides basic logging functionality
00004 //
00005 //
00006 // Copyright (c) 2002-2004 Rob Wiskow
00007 // rob-dev@boxedchaos.com
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022 //
00023 
00024 
00025 #ifndef _WUTIL_LOG_H_
00026 #define _WUTIL_LOG_H_
00027 
00028 #include <string>
00029 #include <time.h>
00030 #include <list>
00031 
00032 namespace wUtil
00033 {
00034 
00036 
00038 
00039 class CLog
00040 {
00041 public:
00043      struct SLogEntry
00044      {
00046           SLogEntry(time_t TimeStamp, unsigned int iSeverity, const std::wstring& sMessage) :
00047                m_TimeStamp(TimeStamp), m_iSeverity(iSeverity), m_sMessage(sMessage) { }
00048 
00050           SLogEntry(void) : m_TimeStamp(0), m_iSeverity(0) { }
00051 
00052           time_t m_TimeStamp;  
00053           unsigned int m_iSeverity;  
00054           std::wstring m_sMessage;  
00055      };
00056 
00057      typedef std::list<SLogEntry> t_LogList;  
00058 
00063      void AddLogEntry(const std::wstring& sMessage, unsigned int iSeverity, time_t TimeStamp)
00064           { m_LogList.push_back(SLogEntry(TimeStamp, iSeverity, sMessage)); }
00065 
00069      void AddLogEntry(const std::wstring& sMessage, unsigned int iSeverity = 5)
00070           { AddLogEntry(sMessage, iSeverity, time(0)); }
00071 
00075      t_LogList GetLogEntries(unsigned int iSeverity = 0) const;
00076 
00081      t_LogList GetLogEntries(unsigned int iHighSeverity, unsigned int iLowSeverity) const;
00082 
00087      void WriteToFile(const std::wstring& sFilename, bool bAppend = true, const std::wstring& sLogHeader = L"") const;
00088 
00090      void Clear(void)
00091           { m_LogList.clear(); }
00092 
00093 protected:
00094      t_LogList m_LogList;  
00095 };
00096 
00097 };
00098 
00099 
00100 #include "unit_tests/wutil_log_unittests.h"
00101 
00102 #endif  // _WUTIL_LOG_H_
00103 

Generated on Wed May 16 23:11:27 2007 for wGui by  doxygen 1.5.1