What is the right way to close and clean boost::log
Hi, I built boost::log in my application library, it created boost::log::sinks::synchronous_sinkboost::log::sinks::text_file_backend and close it by calling the boost::log::core::get()->remove_all_sinks() in destructor of the Log library, then one of my application link to my log library got Segmentation fault when it exited: Program received signal SIGSEGV, Segmentation fault. 0x00007ffff5fdd961 in boost::log::v2_mt_posix::core::remove_all_sinks() () from /usr/lib/x86_64-linux-gnu/libboost_log.so.1.65.1 If I add boost::log::core::get()->remove_all_sinks() in my application main before it return 0, the segmentation was gong, but it stuck. What is the proper right way to close and clean the boost::log? There is a blog suggested to run boost::log::core::get()->remove_all_sinks() when the main end, but that does not seem work. https://www.boost.org/doc/libs/1_62_0/libs/log/doc/html/log/rationale/why_cr... Thank you. Kind regards, - jupiter
On 2020-02-29 14:24, JH via Boost wrote:
Hi,
I built boost::log in my application library, it created boost::log::sinks::synchronous_sinkboost::log::sinks::text_file_backend and close it by calling the boost::log::core::get()->remove_all_sinks() in destructor of the Log library, then one of my application link to my log library got Segmentation fault when it exited:
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff5fdd961 in boost::log::v2_mt_posix::core::remove_all_sinks() () from /usr/lib/x86_64-linux-gnu/libboost_log.so.1.65.1
If I add boost::log::core::get()->remove_all_sinks() in my application main before it return 0, the segmentation was gong, but it stuck.
What is the proper right way to close and clean the boost::log? There is a blog suggested to run boost::log::core::get()->remove_all_sinks() when the main end, but that does not seem work.
https://www.boost.org/doc/libs/1_62_0/libs/log/doc/html/log/rationale/why_cr...
The right way is to call remove_all_sinks at the end of main, and not use logging after that. E.g. you shouldn't use logging library in global destructors. Regarding hanging, you need to investigate what causes the hang.
On 2020-02-29 16:09, Andrey Semashev wrote:
On 2020-02-29 14:24, JH via Boost wrote:
Hi,
I built boost::log in my application library, it created boost::log::sinks::synchronous_sinkboost::log::sinks::text_file_backend and close it by calling the boost::log::core::get()->remove_all_sinks() in destructor of the Log library, then one of my application link to my log library got Segmentation fault when it exited:
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff5fdd961 in boost::log::v2_mt_posix::core::remove_all_sinks() () from /usr/lib/x86_64-linux-gnu/libboost_log.so.1.65.1
If I add boost::log::core::get()->remove_all_sinks() in my application main before it return 0, the segmentation was gong, but it stuck.
What is the proper right way to close and clean the boost::log? There is a blog suggested to run boost::log::core::get()->remove_all_sinks() when the main end, but that does not seem work.
https://www.boost.org/doc/libs/1_62_0/libs/log/doc/html/log/rationale/why_cr...
The right way is to call remove_all_sinks at the end of main, and not use logging after that. E.g. you shouldn't use logging library in global destructors.
Regarding hanging, you need to investigate what causes the hang.
Also, if you're keeping shared pointers referring to the sink backends, you should reset those pointers before returning from main.
Hi Andrey,
On 3/1/20, Andrey Semashev via Boost
The right way is to call remove_all_sinks at the end of main, and not use logging after that. E.g. you shouldn't use logging library in global destructors.
That seems working after removing it from the global destructor.
Regarding hanging, you need to investigate what causes the hang.
That fixed hanging after removed remove_all_sinks from the library global destructor, added it to the main of applications.
Also, if you're keeping shared pointers referring to the sink backends, you should reset those pointers before returning from main.
I don't keep shared pointers in applications, it is in the log library, if the instance of the library exits, the shared pointers will be automatically cleaned up. Hope that is a right implementation. Thanks Andrey, Kind regards, - jupiter
participants (2)
-
Andrey Semashev
-
JH