BsLog.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(const String& msg, UINT32 channel);
  14. UINT32 getChannel() const { return mChannel; }
  15. const String& getMessage() const { return mMsg; }
  16. private:
  17. String mMsg;
  18. UINT32 mChannel;
  19. };
  20. /**
  21. * @brief Used for logging messages. Can categorize messages according to channels, save the log to a file
  22. * and send out callbacks when a new message is added.
  23. *
  24. * @note Thread safe.
  25. */
  26. class BS_UTILITY_EXPORT Log
  27. {
  28. public:
  29. Log();
  30. ~Log();
  31. /**
  32. * @brief Logs a new message.
  33. *
  34. * @param message The message describing the log entry.
  35. * @param channel Channel in which to store the log entry.
  36. */
  37. void logMsg(const String& message, UINT32 channel);
  38. /**
  39. * @brief Removes all log entries.
  40. */
  41. void clear();
  42. /**
  43. * @brief Saves the log file to disk.
  44. */
  45. void saveToFile(const WString& path);
  46. private:
  47. Vector<LogEntry*> mEntries;
  48. BS_RECURSIVE_MUTEX(mMutex);
  49. /**
  50. * @brief Called whenever a new entry is added.
  51. */
  52. void doOnEntryAdded(const LogEntry& entry);
  53. /************************************************************************/
  54. /* SIGNALS */
  55. /************************************************************************/
  56. public:
  57. /**
  58. * @brief Triggered when a new entry in the log is added.
  59. *
  60. * @note
  61. */
  62. Event<void(const LogEntry&)> onEntryAdded;
  63. };
  64. }