BsLog.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "BsLog.h"
  2. #include "BsException.h"
  3. void dbg_VSLog(const BansheeEngine::String& message);
  4. namespace BansheeEngine
  5. {
  6. LogEntry::LogEntry(const String& msg, const String& level)
  7. :mMsg(msg), mChannel(level)
  8. { }
  9. Log::Log()
  10. {
  11. }
  12. Log::~Log()
  13. {
  14. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  15. for(auto iter = mEntries.begin(); iter != mEntries.end(); ++iter)
  16. bs_delete<PoolAlloc>(*iter);
  17. }
  18. void Log::logMsg(const String& message, const String& level)
  19. {
  20. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  21. LogEntry* newEntry = bs_new<LogEntry, PoolAlloc>(message, level);
  22. mEntries.push_back(newEntry);
  23. dbg_VSLog(message);
  24. doOnEntryAdded(*newEntry);
  25. }
  26. void Log::clear()
  27. {
  28. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  29. for(auto iter = mEntries.begin(); iter != mEntries.end(); ++iter)
  30. bs_delete<PoolAlloc>(*iter);
  31. mEntries.clear();
  32. }
  33. void Log::saveToFile(const WString& path)
  34. {
  35. // TODO - Save the log as HTML
  36. BS_EXCEPT(NotImplementedException, "Log save to file not yet implemented.");
  37. }
  38. void Log::doOnEntryAdded(const LogEntry& entry)
  39. {
  40. onEntryAdded(entry);
  41. }
  42. }
  43. // TODO: Debug only - Remove later
  44. #include <windows.h>
  45. void dbg_VSLog(const BansheeEngine::String& message)
  46. {
  47. OutputDebugString(message.c_str());
  48. OutputDebugString("\n");
  49. }