3

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();      
}
sorush-r
  • 10,490
  • 17
  • 89
  • 173
  • You can implement a sink of your own, wrapping an underlying sink, so that you can cache log messages before creating the console window and just forward all log messages when everything is ready. – Sprite Jul 06 '22 at 19:36

0 Answers0