BsLog.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 all existing log entries.
  45. */
  46. Vector<LogEntry> getEntries() const;
  47. /**
  48. * @brief Returns the latest unread entry from the log queue, and removes the entry from the unread entries
  49. * list.
  50. *
  51. * @param entry Entry that was read, or undefined if no entries exist.
  52. *
  53. * @returns True if an unread entry was retrieved, false otherwise.
  54. */
  55. bool getUnreadEntry(LogEntry& entry);
  56. private:
  57. friend class Debug;
  58. /**
  59. * @brief Returns all log entries, including those marked as unread.
  60. */
  61. Vector<LogEntry> getAllEntries() const;
  62. Vector<LogEntry> mEntries;
  63. Queue<LogEntry> mUnreadEntries;
  64. BS_RECURSIVE_MUTEX(mMutex);
  65. };
  66. }