Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The file is overwritten when the program runs multiple times #2633

Closed
chyczcool opened this issue Feb 7, 2023 · 1 comment
Closed

The file is overwritten when the program runs multiple times #2633

chyczcool opened this issue Feb 7, 2023 · 1 comment

Comments

@chyczcool
Copy link

#include <stdlib.h>
#include
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"

int main()
{
try
{
spdlog::basic_logger_mt("basic_logger", "logs/basic-log.log");
}
catch (const spdlog::spdlog_ex& ex)
{
std::cout << "Log init failed: " << ex.what() << std::endl;
}

auto logger = spdlog::get("basic_logger");
if (NULL == logger)
{
    std::cout << "get logger error." << std::endl;
}

int i = 0;
while (i < 10)
{

    logger->info("This is basic_logger .");
    Sleep(1000);
    i++;
}

}
=======Dividing line=========
The above is a log test program output to a file. After the first run, the printed content appears correctly in the log file, but it does not appear to be updated during the second run. In fact, the file generated during the first run should be overwritten during the second run. What we expect is not to overwrite the file. How can we solve this problem? Other file longers also have the same problem...

@tt4g
Copy link
Contributor

tt4g commented Feb 7, 2023

Duplicate #937

spdlog does not support writing to a single file from multiple processes.
Use unique file names for each process.

@gabime gabime closed this as completed Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants