CmLog.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "CmLog.h"
  2. #include "boost/signal.hpp"
  3. void dbg_VSLog(const CamelotFramework::String& message);
  4. namespace CamelotFramework
  5. {
  6. LogEntry::LogEntry(const String& msg, const String& level)
  7. :mMsg(msg), mChannel(level)
  8. { }
  9. Log::Log(const String& logFilePath, bool autoSave, bool suppressFileOutput)
  10. :mAutoSave(autoSave), mSuppressFileOutput(suppressFileOutput), mSaveFilePath(logFilePath)
  11. {
  12. }
  13. Log::~Log()
  14. {
  15. flush();
  16. for(auto iter = mEntries.begin(); iter != mEntries.end(); ++iter)
  17. cm_delete<PoolAlloc>(*iter);
  18. }
  19. void Log::logMsg(const String& message, const String& level)
  20. {
  21. LogEntry* newEntry = cm_new<LogEntry, PoolAlloc>(message, level);
  22. mEntries.push_back(newEntry);
  23. doOnEntryAdded(*newEntry);
  24. dbg_VSLog(message);
  25. if(mAutoSave)
  26. flush();
  27. }
  28. void Log::clear()
  29. {
  30. for(auto iter = mEntries.begin(); iter != mEntries.end(); ++iter)
  31. cm_delete<PoolAlloc>(*iter);
  32. mEntries.clear();
  33. if(mAutoSave)
  34. flush();
  35. }
  36. void Log::flush()
  37. {
  38. if(mSuppressFileOutput)
  39. return;
  40. // TODO - Write to disk and throw exception if it can't
  41. }
  42. void Log::doOnEntryAdded(const LogEntry& entry)
  43. {
  44. onEntryAdded(entry);
  45. }
  46. }
  47. // TODO: Debug only - Remove later
  48. #include <windows.h>
  49. void dbg_VSLog(const CamelotFramework::String& message)
  50. {
  51. OutputDebugString(message.c_str());
  52. OutputDebugString("\n");
  53. }