CBasicLogConfigurator.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 "CLogger.h"
  12. class CConsoleHandler;
  13. class JsonNode;
  14. /// The class CBasicLogConfigurator reads log properties from settings.json and
  15. /// sets up the logging system.
  16. class DLL_LINKAGE CBasicLogConfigurator
  17. {
  18. public:
  19. CBasicLogConfigurator(const std::string & filePath, CConsoleHandler * console);
  20. /// Configures the logging system by parsing the logging settings. It adds the console target and the file target to the global logger.
  21. /// If the append parameter is true, the log file will be appended to. Otherwise the log file will be truncated.
  22. /// Throws std::runtime_error if the configuration has errors.
  23. void configure(bool appendToLogFile = true);
  24. /// Configures a default logging system by adding the console target and the file target to the global logger.
  25. /// If the append parameter is true, the log file will be appended to. Otherwise the log file will be truncated.
  26. void configureDefault(bool appendToLogFile = true);
  27. private:
  28. ELogLevel::ELogLevel getLogLevel(const std::string & level) const;
  29. EConsoleTextColor::EConsoleTextColor getConsoleColor(const std::string & colorName) const;
  30. std::string filePath;
  31. CConsoleHandler * console;
  32. };