Is there a way to pause spdlog's logger (or a single sink)?

Viewed 36

I am using spdlog's asynchronous logging. I create a console window and redirect stdout and stderr to it at a late point in the application. spdlog works fine after I have the window ready. But before that, I miss the logs. Basically, I have the following structure:

main()
{
   init_spdlog();            // An asynchronous sink on stdout and stderr
   some_logs();              // I miss this logs
   create_console_window();
   do_some_more_logs();      // These work fine
}

I need a means to "pause" the logger, or somehow make it "buffer" the logs and avoid flushing them until explicitly specified. Like:

main()
{
   init_spdlog(); 
   pause_logger();           // Buffer logs, don't flush to stdout,stderr
   some_logs();              // Not shown, but not lost
   create_console_window();
   resume_logger();          // Don't buffer the logs, flush normally
   do_some_more_logs();      
}
0 Answers
Related