LogFailSafe.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning (disable : 4786)
  14. #ifndef _LOGFAILSAFE_HPP__
  15. #define _LOGFAILSAFE_HPP__
  16. #include "jlib.hpp"
  17. #include "jstring.hpp"
  18. #include "jutil.hpp" // for StringArray
  19. #include "loggingcommon.hpp"
  20. #include "LogSerializer.hpp"
  21. interface ILogFailSafe : IInterface
  22. {
  23. virtual void Add(const char*, const StringBuffer& strContents)=0;//
  24. virtual void Add(const char*,IInterface& pIn)=0;
  25. virtual StringBuffer& GenerateGUID(StringBuffer& GUID,const char* seed="") = 0;
  26. virtual void AddACK(const char* GUID)=0;
  27. virtual void RollCurrentLog()=0;
  28. virtual void RollOldLogs()=0;
  29. virtual bool FindOldLogs() = 0;
  30. virtual void LoadOldLogs(StringArray& oldLogData) = 0;
  31. virtual void SplitLogRecord(const char* requestStr,StringBuffer& GUID, StringBuffer& Cache)=0;
  32. virtual void SafeRollover() = 0;
  33. virtual void RolloverAllLogs()=0;//
  34. virtual bool PopPendingLogRecord(StringBuffer& GUID, StringBuffer& cache) = 0;//
  35. };
  36. extern LOGGINGCOMMON_API ILogFailSafe* createFailSafeLogger(const char* logType="", const char* logsdir="./logs");
  37. extern LOGGINGCOMMON_API ILogFailSafe* createFailSafeLogger(const char* pszService, const char* logType="", const char* logsdir="./logs");
  38. class CLogFailSafe : implements ILogFailSafe, public CInterface
  39. {
  40. CLogSerializer m_Added;
  41. CLogSerializer m_Cleared;
  42. static CLogFailSafe* m_Instance;
  43. StringBuffer m_LogType;
  44. StringArray m_UnsentLogs;
  45. StringBuffer m_logsdir;
  46. StringBuffer m_LogService;//
  47. CriticalSection m_critSec;//
  48. GuidMap m_PendingLogs;//
  49. private:
  50. void createNew(const char* logType);
  51. void loadFailed(const char* logType);
  52. StringBuffer& getReceiveFileName(const char* sendFileName, StringBuffer& recieveName);
  53. StringBuffer& ExtractFileName(const char* fileName,StringBuffer& FileName);
  54. void loadPendingLogReqsFromExistingLogFiles();//
  55. void generateNewFileNames(StringBuffer& sendingFile, StringBuffer& receivingFile);//
  56. public:
  57. IMPLEMENT_IINTERFACE;
  58. CLogFailSafe();
  59. CLogFailSafe(const char* logType, const char* logsdir);
  60. CLogFailSafe(const char* pszService, const char* logType, const char* logsdir);
  61. virtual ~CLogFailSafe();
  62. StringBuffer& GenerateGUID(StringBuffer& GUID,const char* seed="");
  63. virtual void Add(const char*, const StringBuffer& strContents);//
  64. virtual void Add(const char*,IInterface& pIn);
  65. virtual void AddACK(const char* GUID);
  66. virtual void RollCurrentLog();
  67. virtual void RollOldLogs();
  68. virtual bool FindOldLogs();
  69. virtual void LoadOldLogs(StringArray& oldLogData);
  70. virtual void SplitLogRecord(const char* requestStr,StringBuffer& GUID, StringBuffer& Cache);
  71. virtual void SafeRollover();
  72. virtual void RolloverAllLogs();//
  73. virtual bool PopPendingLogRecord(StringBuffer& GUID, StringBuffer& cache);//
  74. };
  75. #endif // !_LOGFAILSAFE_HPP__