BsLog.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. namespace bs
  6. {
  7. /** @addtogroup Debug
  8. * @{
  9. */
  10. /** A single log entry, containing a message and a channel the message was recorded on. */
  11. class BS_UTILITY_EXPORT LogEntry
  12. {
  13. public:
  14. LogEntry() { }
  15. LogEntry(const String& msg, UINT32 channel);
  16. /** Channel the message was recorded on. */
  17. UINT32 getChannel() const { return mChannel; }
  18. /** Text of the message. */
  19. const String& getMessage() const { return mMsg; }
  20. private:
  21. String mMsg;
  22. UINT32 mChannel;
  23. };
  24. /**
  25. * Used for logging messages. Can categorize messages according to channels, save the log to a file
  26. * and send out callbacks when a new message is added.
  27. *
  28. * @note Thread safe.
  29. */
  30. class BS_UTILITY_EXPORT Log
  31. {
  32. public:
  33. Log();
  34. ~Log();
  35. /**
  36. * Logs a new message.
  37. *
  38. * @param[in] message The message describing the log entry.
  39. * @param[in] channel Channel in which to store the log entry.
  40. */
  41. void logMsg(const String& message, UINT32 channel);
  42. /** Removes all log entries. */
  43. void clear();
  44. /** Removes all log entries in a specific channel. */
  45. void clear(UINT32 channel);
  46. /** Returns all existing log entries. */
  47. Vector<LogEntry> getEntries() const;
  48. /**
  49. * Returns the latest unread entry from the log queue, and removes the entry from the unread entries list.
  50. *
  51. * @param[out] entry Entry that was retrieved, or undefined if no entries exist.
  52. * @return True if an unread entry was retrieved, false otherwise.
  53. */
  54. bool getUnreadEntry(LogEntry& entry);
  55. /**
  56. * Returns the last available log entry.
  57. *
  58. * @param[out] entry Entry that was retrieved, or undefined if no entries exist.
  59. * @return True if an entry was retrieved, false otherwise.
  60. */
  61. bool getLastEntry(LogEntry& entry);
  62. /**
  63. * Returns a hash value that is modified whenever entries in the log change. This can be used for
  64. * checking for changes by external systems.
  65. */
  66. UINT64 getHash() const { return mHash; }
  67. private:
  68. friend class Debug;
  69. /** Returns all log entries, including those marked as unread. */
  70. Vector<LogEntry> getAllEntries() const;
  71. Vector<LogEntry> mEntries;
  72. Queue<LogEntry> mUnreadEntries;
  73. UINT64 mHash;
  74. mutable RecursiveMutex mMutex;
  75. };
  76. /** @} */
  77. }