2
0

CmLog.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. //OGRE_EXCEPT(::Ogre::Exception::ERR_INTERNAL_ERROR,
  42. // "Cannot create log file at " + mSaveFilePath,
  43. // "Log::save()");
  44. }
  45. void Log::doOnEntryAdded(const LogEntry& entry)
  46. {
  47. onEntryAdded(entry);
  48. }
  49. }
  50. // TODO: Debug only - Remove later
  51. #include <windows.h>
  52. void dbg_VSLog(const CamelotFramework::String& message)
  53. {
  54. OutputDebugString(message.c_str());
  55. OutputDebugString("\n");
  56. }