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

rotating_file_sink_mt doesn't work in fork mode #3337

Closed
maordadush opened this issue Feb 6, 2025 · 3 comments
Closed

rotating_file_sink_mt doesn't work in fork mode #3337

maordadush opened this issue Feb 6, 2025 · 3 comments

Comments

@maordadush
Copy link

I set up spdlog in the parent before fork()

auto file_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(file_logger_path, 10  * 1024 * 1024, 0);
file_sink->set_pattern("[%m/%d/%Y %H:%M:%S.%e] [%^%l%$] %v");
auto file_logger = std::make_shared<spdlog::logger>("file_logger", file_sink);

Log rotation doesn't work if I run my program with a non-root user, but with a root user, it works.
if I disable the fork mode and run my program with a non-root user the log rotation works

@tt4g
Copy link
Contributor

tt4g commented Feb 6, 2025

Do not set up spdlog in the parent process before fork().
After fork(), resources created with C++ std::thread and std::mutex will not work properly.

See:

@tt4g
Copy link
Contributor

tt4g commented Feb 7, 2025

See also: #2874 (comment)

@maordadush
Copy link
Author

Thanks!

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

2 participants