Boost Log causes crash when trying first log statement (when not Administrator)

泪湿孤枕 提交于 2019-12-04 09:55:50

Okay, I figured it out.

The issue was this line here, setting up the text backend:

boost::shared_ptr< boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend > > textFileSink(new boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend >
    boost::log::keywords::file_name = "log_%7N.log",                // file name pattern
    boost::log::keywords::rotation_size = 16384                     // rotation size, in characters
    ));

There was definitely a temporary log file being written to the local directory (a Program Files directory, which is bad). Based on the documentation here, I saw that there is a temporary file written, and then passed to the file collector.

So for the solution, I changed the code to this:

boost::shared_ptr< boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend > > textFileSink(new boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend >(
    boost::log::keywords::file_name = appData + L"\\log_%7N.log",   // file name pattern
    boost::log::keywords::rotation_size = 16384                         // rotation size, in characters
    ));

Notice that I am now specifying the file_name as being in the AppData directory instead.

This solved the problem.

I have a hard time believing that I am the first one to run into this issue, but I could not find this anywhere on the web. This would be a commonly recurring problem for windows developers, so hopefully this is helpful to someone else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!