CmLog.cpp 1.2 KB

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