You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loggersetup.cpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "loggersetup.h"
  2. #include "sol.hpp"
  3. namespace vtk {
  4. LoggerSetup::LoggerSetup() {
  5. mLogFolder = "logs";
  6. }
  7. void LoggerSetup::setLogFolder(const std::string& path) {
  8. mLogFolder = path;
  9. }
  10. void LoggerSetup::setup() {
  11. std::vector<spdlog::sink_ptr> logSinks;
  12. logSinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>("logs/log", 1048576 * 5, 3));
  13. logSinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_st>());
  14. auto generalLogger = std::make_shared<spdlog::logger>("general", begin(logSinks), end(logSinks));
  15. auto fileLogger = std::make_shared<spdlog::logger>("file", begin(logSinks), end(logSinks));
  16. auto scriptLogger = std::make_shared<spdlog::logger>("script", begin(logSinks), end(logSinks));
  17. spdlog::register_logger(generalLogger);
  18. spdlog::register_logger(fileLogger);
  19. spdlog::register_logger(scriptLogger);
  20. spdlog::set_level(spdlog::level::debug);
  21. }
  22. void LoggerSetup::registerScriptInterface(sol::state& lua) {
  23. lua.set_function("log_info", [](std::string arg) {
  24. spdlog::get("script")->info(arg);
  25. });
  26. lua.set_function("log_debug", [](std::string arg) {
  27. spdlog::get("script")->debug(arg);
  28. });
  29. lua.set_function("log_warn", [](std::string arg) {
  30. spdlog::get("script")->warn(arg);
  31. });
  32. lua.set_function("log_error", [](std::string arg) {
  33. spdlog::get("script")->error(arg);
  34. });
  35. }
  36. }