BsLog.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. #include "BsEvent.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief A single log entry, containing a message and a channel the message
  8. * was recorded on.
  9. */
  10. class BS_UTILITY_EXPORT LogEntry
  11. {
  12. public:
  13. LogEntry() { }
  14. LogEntry(const String& msg, UINT32 channel);
  15. UINT32 getChannel() const { return mChannel; }
  16. const String& getMessage() const { return mMsg; }
  17. private:
  18. String mMsg;
  19. UINT32 mChannel;
  20. };
  21. /**
  22. * @brief Used for logging messages. Can categorize messages according to channels, save the log to a file
  23. * and send out callbacks when a new message is added.
  24. *
  25. * @note Thread safe.
  26. */
  27. class BS_UTILITY_EXPORT Log
  28. {
  29. public:
  30. Log();
  31. ~Log();
  32. /**
  33. * @brief Logs a new message.
  34. *
  35. * @param message The message describing the log entry.
  36. * @param channel Channel in which to store the log entry.
  37. */
  38. void logMsg(const String& message, UINT32 channel);
  39. /**
  40. * @brief Removes all log entries.
  41. */
  42. void clear();
  43. /**
  44. * @brief Returns the latest unread entry from the log queue, and removes the entry from the unread entries
  45. * list.
  46. *
  47. * @param entry Entry that was read, or undefined if no entries exist.
  48. *
  49. * @returns True if an unread entry was retrieved, false otherwise.
  50. */
  51. bool getUnreadEntry(LogEntry& entry);
  52. private:
  53. friend class Debug;
  54. Vector<LogEntry*> mEntries;
  55. Queue<LogEntry*> mUnreadEntries;
  56. BS_RECURSIVE_MUTEX(mMutex);
  57. };
  58. }