quill icon indicating copy to clipboard operation
quill copied to clipboard

Multiple Sinks for a Single Logger Not Working

Open ottoborden opened this issue 4 months ago • 3 comments

Describe the bug The docs state: "When creating a logger, one or more sinks for that logger can be specified. Sinks can only be registered during the logger creation." And I can see that the Frontend::create_or_get_logger() method takes a std::initializer_list of Sinks. However I have not been able to get a logger that will log to both console and a file.

To Reproduce

#ifdef NDEBUG
#else
#define QUILL_IMMEDIATE_FLUSH true
#define QUILL_COMPILE_ACTIVE_LOG_LEVEL QUILL_COMPILE_ACTIVE_LOG_LEVEL_TRACE_L3
#endif

....

  // log everything to console
  auto console_sink = quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
      "console_sink");
  // log everything to file
  auto file_sink = quill::Frontend::create_or_get_sink<quill::FileSink>(
      "debug_logs.txt", []() {
        quill::FileSinkConfig cfg;
        cfg.set_open_mode('w');
        cfg.set_filename_append_option(
            quill::FilenameAppendOption::StartDateTime);
        return cfg;
      }(),
      quill::FileEventNotifier{});
  // create logger
  quill::Logger *logger = quill::Frontend::create_or_get_logger(
      "root", {std::move(console_sink), std::move(file_sink)});
  logger->set_log_level(quill::LogLevel::TraceL3);

Expected Behaviour I would expect it to log to both sinks concurrently. However, with the code above, I only see the logs in the console. The debug_logs.txt file does get created, but it is empty. If I remove the std::move(console_sink) in the code above it logs to the file as expected.

Environment

  • Operating System: Windows 11
  • Compiler: Microsoft Visual C++ 2022, MSVC 19

Additional context None that would be useful. I'm using a custom memory allocator (mi-malloc) but I can't imagine that is an issue here.

ottoborden avatar Oct 13 '24 05:10 ottoborden