1

I have working logging in Visual studio project using spdlog. I used the same project in Qt creator, then the spdlog logging does not output anything. But the std::cout still works and prints to Qt creator's application output window.

std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("multisink.txt", true));
auto appLogger = std::make_shared<spdlog::logger>("appLogger", begin(sinks), end(sinks));
appLogger->set_level(spdlog::level::debug);
spdlog::register_logger(appLogger);
spdlog::flush_on(spdlog::level::debug);    
appLogger->warn("this should appear in both console and file");
Main
  • 1,804
  • 3
  • 20
  • 28

2 Answers2

1

Yes, the application output does not output the spdlogs. But, I manage to output to terminal by following steps.

  1. Go to Projects, then choose Run configuration for selected kit
  2. In run settings, check the "Run in terminal" option
  3. Next, add console to CONFIG in Project pro file
  4. Clean the project
  5. Build and run.

If these steps don't help, you can delete entire build directory and run the steps again.

Main
  • 1,804
  • 3
  • 20
  • 28
1

I had the same issue, and only way I could get the log messages to appear in the application output tab was to use the msvc logger.

auto sink   = std::make_shared<spdlog::sinks::msvc_sink_mt>();
auto logger = std::make_shared<spdlog::logger>("msvc_logger", sink);

The flip side of this logger is that it doesn't print to the console/terminal.

To write to both the application output and the console using the same logger you could create a distributed sink as this:

auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
auto msvc_sink    = std::make_shared<spdlog::sinks::msvc_sink_mt>();
auto dist_sink    = std::make_shared<spdlog::sinks::dist_sink_st>();
dist_sink->add_sink(msvc_sink);
dist_sink->add_sink(console_sink);
auto logger = std::make_shared<spdlog::logger>("multi_sink", dist_sink)
logger->info("testing multiple sinks");
rakke
  • 6,819
  • 2
  • 26
  • 28