CmLog.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. #include "boost/signal.hpp"
  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 CM_UTILITY_EXPORT LogEntry
  11. {
  12. public:
  13. LogEntry(const String& msg, const String& channel);
  14. const String& getChannel(void) { return mChannel; }
  15. const String& getMessage(void) { return mMsg; }
  16. private:
  17. String mMsg;
  18. String 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. class CM_UTILITY_EXPORT Log
  25. {
  26. public:
  27. Log();
  28. ~Log();
  29. /**
  30. * @brief Logs a new message.
  31. *
  32. * @param message The message describing the log entry.
  33. * @param channel Channel in which to store the log entry.
  34. */
  35. void logMsg(const String& message, const String& channel);
  36. /**
  37. * @brief Removes all log entries.
  38. */
  39. void clear();
  40. /**
  41. * @brief Saves the log file to disk.
  42. */
  43. void saveToFile(const WString& path);
  44. private:
  45. Vector<LogEntry*>::type mEntries;
  46. /**
  47. * @brief Called whenever a new entry is added.
  48. */
  49. void doOnEntryAdded(const LogEntry& entry);
  50. /************************************************************************/
  51. /* SIGNALS */
  52. /************************************************************************/
  53. public:
  54. /**
  55. * @brief Triggered when a new entry in the log is added.
  56. */
  57. boost::signal<void(const LogEntry&)> onEntryAdded;
  58. };
  59. }