Async logger crash after fork()
Here is my situation: A main process have a global async logger, and then it will fork several subprocesses. When the subprocess call log function of the global async logger, the process dead because the _worker_thread in the new process is no longer the thread in the main process.
Maybe we can do some cleanup when _worker_thread::id != this_thread::get_id() or so?
Thanks.
spdlog does not support multi process. I dont think there is a quick workaround
Does that mean I can't use spdlog in daemon?
it depends which type of daemon of course
I'm working on a server (reading data through socket), and it's crashing when I run in as daemon. Are there any special steps I should be taking, in regards to spdlog library?
make sure you create the loggers after the fork
I have logger declared in global scope as std::shared_ptr<spdlog::logger> logger, then I do the daemonization process (fork, setsid, closing stdin, stdout and stderr) and after that I create a temporary logger and assign it to logger. When I try call logger->info(...) it crashes with segfault. I'm using syslog and file logger, if it makes any difference.
I managed to got it working, but seems I have to manually call flush when writing to file log. Is there some option I missed, or is that part of library's behavior?
there is a force_flush param you can use. please see the docs