CBasicLogConfigurator.h 1.6 KB

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