CLogManager.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * CLogManager.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. class CGLogger;
  12. class CLoggerDomain;
  13. /**
  14. * The log manager is a global storage of all logger objects.
  15. */
  16. class DLL_LINKAGE CLogManager : public boost::noncopyable
  17. {
  18. public:
  19. /**
  20. * Gets an instance of the log manager.
  21. *
  22. * @return an instance of the log manager
  23. */
  24. static CLogManager * get();
  25. /**
  26. * Adds a logger. The log manager holds strong ownership of the logger object.
  27. *
  28. * @param logger The logger to add.
  29. */
  30. void addLogger(CGLogger * logger);
  31. /**
  32. * Gets a logger by domain.
  33. *
  34. * @param domain The domain of the logger.
  35. * @return a logger by domain or nullptr if the logger was not found
  36. */
  37. CGLogger * getLogger(const CLoggerDomain & domain);
  38. /**
  39. * Destructor.
  40. */
  41. ~CLogManager();
  42. private:
  43. /**
  44. * Constructor.
  45. */
  46. CLogManager();
  47. /** The instance of the log manager. */
  48. static CLogManager * instance;
  49. /** The loggers map where the key is the logger name and the value the corresponding logger. */
  50. std::map<std::string, CGLogger *> loggers;
  51. /** The shared mutex for providing synchronous thread-safe access to the log manager. */
  52. mutable boost::shared_mutex mx;
  53. /** The unique mutex for providing thread-safe singleton access. */
  54. static boost::mutex smx;
  55. };