Search code examples
c++qtspdlog

Why Qt Creator's application output does not print from spdlog logger


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");

Solution

  • 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.