spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

Problem adding file sync after spdlog has been setup...

Open htartisan opened this issue 1 month ago • 7 comments

I am working on a new project where I am trying to use speedlog. I have used it in the past and it seemed to work fine.

In the new project, I am creating an initial logging configuration where I create a "main" logger,, and I add a console log sink (see below).

 auto m_mainLogger =
        std::make_shared<spdlog::logger>(m_sLogName.c_str());

 auto m_consoleSink =
            std::make_shared<spdlog::sinks::stdout_color_sink_mt>();

 m_mainLogger->sinks().push_back(m_consoleSink);

That seems to work fine, and I can see (colored) log output to the console.

However, after the application configuration is loaded, I then try to add a file sink to the "main" logger (see below).

auto m_fileSink =
                std::make_shared<spdlog::sinks::rotating_file_sink_mt>
                (
                    sLogFilePath,
                    MAX_LOG_FILE_SIZE,
                    MAX_LOG_FILES,
                    ROTATE_LOGS_ON_STARTUP
                );

m_mainLogger->sinks().push_back(m_fileSink);

I can then see that the log file is opened, but I never see any log text in the log file.

Is there an issue adding additional log sinks once the initial logging configuration has been setup?

htartisan avatar Jan 07 '25 21:01 htartisan