CBasicLogConfigurator.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * CBasicLogConfigurator.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. VCMI_LIB_NAMESPACE_BEGIN
  12. class CConsoleHandler;
  13. class JsonNode;
  14. enum class EConsoleTextColor : int8_t;
  15. /// The class CBasicLogConfigurator reads log properties from settings.json and
  16. /// sets up the logging system. Make sure that you use the same configurator object to
  17. /// initialize the whole logging system. If you don't do so, the log file will be overwritten/truncated.
  18. class DLL_LINKAGE CBasicLogConfigurator
  19. {
  20. public:
  21. CBasicLogConfigurator(boost::filesystem::path filePath, CConsoleHandler * const console);
  22. /// Configures the logging system by parsing the logging settings. It adds the console target and the file target to the global logger.
  23. /// Doesn't throw, but logs on success or fault.
  24. void configure();
  25. /// Configures a default logging system by adding the console target and the file target to the global logger.
  26. void configureDefault();
  27. /// Removes all targets from the global logger.
  28. void deconfigure();
  29. private:
  30. // Gets ELogLevel enum from string. (Should be moved to CLogger as a separate function?)
  31. // Throws: std::runtime_error
  32. static ELogLevel::ELogLevel getLogLevel(const std::string & level);
  33. // Gets EConsoleTextColor enum from strings. (Should be moved to CLogger as a separate function?)
  34. // Throws: std::runtime_error
  35. static EConsoleTextColor getConsoleColor(const std::string & colorName);
  36. boost::filesystem::path filePath;
  37. CConsoleHandler * console;
  38. bool appendToLogFile;
  39. };
  40. VCMI_LIB_NAMESPACE_END