CBasicLogConfigurator.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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(const boost::filesystem::path & file_path, CConsoleHandler * const console);
  21. CBasicLogConfigurator(boost::filesystem::path && file_path, 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. private:
  28. // Gets ELogLevel enum from string. (Should be moved to CLogger as a separate function?)
  29. // Throws: std::runtime_error
  30. static ELogLevel::ELogLevel getLogLevel(const std::string & level);
  31. // Gets EConsoleTextColor enum from strings. (Should be moved to CLogger as a separate function?)
  32. // Throws: std::runtime_error
  33. static EConsoleTextColor::EConsoleTextColor getConsoleColor(const std::string & colorName);
  34. boost::filesystem::path file_path;
  35. CConsoleHandler * console;
  36. bool appendToLogFile;
  37. };