BsLog.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "BsLog.h"
  2. #include "BsException.h"
  3. namespace BansheeEngine
  4. {
  5. LogEntry::LogEntry(const String& msg, UINT32 channel)
  6. :mMsg(msg), mChannel(channel)
  7. { }
  8. Log::Log()
  9. {
  10. }
  11. Log::~Log()
  12. {
  13. clear();
  14. }
  15. void Log::logMsg(const String& message, UINT32 channel)
  16. {
  17. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  18. mUnreadEntries.push(LogEntry(message, channel));
  19. }
  20. void Log::clear()
  21. {
  22. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  23. mEntries.clear();
  24. while (!mUnreadEntries.empty())
  25. mUnreadEntries.pop();
  26. }
  27. bool Log::getUnreadEntry(LogEntry& entry)
  28. {
  29. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  30. if (mUnreadEntries.empty())
  31. return false;
  32. entry = mUnreadEntries.front();
  33. mUnreadEntries.pop();
  34. mEntries.push_back(entry);
  35. return true;
  36. }
  37. Vector<LogEntry> Log::getEntries() const
  38. {
  39. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  40. return mEntries;
  41. }
  42. Vector<LogEntry> Log::getAllEntries() const
  43. {
  44. Vector<LogEntry> entries;
  45. {
  46. BS_LOCK_RECURSIVE_MUTEX(mMutex);
  47. for (auto& entry : mEntries)
  48. entries.push_back(entry);
  49. Queue<LogEntry> unreadEntries = mUnreadEntries;
  50. while (!unreadEntries.empty())
  51. {
  52. entries.push_back(unreadEntries.front());
  53. unreadEntries.pop();
  54. }
  55. }
  56. return entries;
  57. }
  58. }