spdlog
spdlog copied to clipboard
Dont want spdlog crash on exceptions !!
Hi,
I have seen spdlog crashes sometimes due to some exceptions. For example below
terminate called after throwing an instance of 'spdlog::spdlog_ex' what: async log: thread log does not exist anymore.
I understand it crashed due to exit call from code. I dont want spdlog to crashes but ignore, and i will handle code errors myself, How could i do that.
Thanks very much for suggestions and help.
Caused by using async logger even though the thread pool has been deleted.
https://github.com/gabime/spdlog/blob/ad08f13aacc92b5e38c4a77f9cabd24d54fd53b1/include/spdlog/async_logger-inl.h#L27-L37
spdlog does not work after calling spdlog::shutdown().
Thanks,
Is it possible to avoid SPDLOG crashing even though its called after thread pool is deleted?
Yes.
How?
thanks.
My apologies, I misread your comment.
The async logger that uses the thread pool will not work after the thread pool is deleted. Non async logger does not use a thread pool so it continues to work even after the thread pool is deleted.
Note: After spdlog::shutdown() is called, spdlog's internal resources are released, so some features (including the thread pool) will not work.
That being said, I think the async sink_it_() better not to throw anyway and call err_handler_ instead. Or maybe better just wrap with
try {....}
SPDLOG_LOGGER_CATCH(msg.source)
PR is welcome
hi,
I was reading in some links, i can create a separate thread pool for spdlog then it wont be impacted from others. Will it impact the logging in someway or if there is any other impact? Sorry dont know much internals of how spdlog works.
Thanks for help
Custom thread pools are not managed by spdlog, so you are responsible for destroying the pools yourself.
Wiki: https://github.com/gabime/spdlog/wiki/6.-Asynchronous-logging#construct-directly-and-use-a-custom-thread-pool
thanks, I checked, creating a separate thread pool does not suit my setup.
can i use some option when i call create_async_nb, so it does not crash but some error trace only ?
auto new_logger = spdlog::create_async_nbspdlog::sinks::stdout_sink_mt("console_logger");
The async_logger custom steps are all described in the Wiki.
And spdlog::create_async_nb() is the factory function for the thread pool and async logger. What is done in this function is just one of the Wiki setup steps.
https://github.com/gabime/spdlog/blob/5a589438d2d2abc67bdbec2aad7e2a94800c00ea/include/spdlog/async.h#L69-L73
https://github.com/gabime/spdlog/blob/5a589438d2d2abc67bdbec2aad7e2a94800c00ea/include/spdlog/async.h#L61
https://github.com/gabime/spdlog/blob/5a589438d2d2abc67bdbec2aad7e2a94800c00ea/include/spdlog/async.h#L31-L58
Fixed in 1fba68bfe238629733b49d4c9d576556f7788585