Note that there are some explanatory texts on larger screens.

plurals
  1. POboost.log auto_flush files are not stored when app is crashed
    primarykey
    data
    text
    <p>Recently I started to play with boost.log, and bumped into an issue that if an unhanded exception is thrown no log messages are written to the log file. I am using rolling text files and auto-flash option is set on.</p> <p>Here is the modified source from the samples:</p> <pre><code>#include &lt;stdexcept&gt; #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;functional&gt; #include &lt;boost/ref.hpp&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/date_time/gregorian/gregorian.hpp&gt; #include &lt;boost/date_time/posix_time/posix_time_types.hpp&gt; #include &lt;boost/thread/thread.hpp&gt; #include &lt;boost/thread/barrier.hpp&gt; #include &lt;boost/log/common.hpp&gt; #include &lt;boost/log/filters.hpp&gt; #include &lt;boost/log/formatters.hpp&gt; #include &lt;boost/log/attributes.hpp&gt; #include &lt;boost/log/sinks.hpp&gt; #include &lt;boost/log/utility/empty_deleter.hpp&gt; #include &lt;boost/log/utility/record_ordering.hpp&gt; namespace logging = boost::log; namespace attrs = boost::log::attributes; namespace src = boost::log::sources; namespace sinks = boost::log::sinks; namespace fmt = boost::log::formatters; namespace keywords = boost::log::keywords; using boost::shared_ptr; using namespace boost::gregorian; enum { LOG_RECORDS_TO_WRITE = 100, LOG_RECORDS_TO_WRITE_BEFORE_EXCEPTION = 10, THREAD_COUNT = 10 }; BOOST_LOG_DECLARE_GLOBAL_LOGGER(test_lg, src::logger_mt) //! This function is executed in multiple threads void thread_fun(boost::barrier&amp; bar) { // Wait until all threads are created bar.wait(); // Here we go. First, identify the thread. BOOST_LOG_SCOPED_THREAD_TAG("ThreadID", boost::thread::id, boost::this_thread::get_id()); // Now, do some logging for (unsigned int i = 0; i &lt; LOG_RECORDS_TO_WRITE; ++i) { BOOST_LOG(get_test_lg()) &lt;&lt; "Log record " &lt;&lt; i; if(i &gt; LOG_RECORDS_TO_WRITE_BEFORE_EXCEPTION) { BOOST_THROW_EXCEPTION(std::exception("unhandled exception")); } } } int main(int argc, char* argv[]) { try { typedef sinks::synchronous_sink&lt; sinks::text_file_backend &gt; file_sink; shared_ptr&lt; file_sink &gt; sink(new file_sink( keywords::file_name = L"%Y%m%d_%H%M%S_%5N.log", // file name pattern keywords::rotation_size = 10 * 1024 * 1024, // rotation size, in characters keywords::auto_flush = true // make each log record flushed to the file )); // Set up where the rotated files will be stored sink-&gt;locked_backend()-&gt;set_file_collector(sinks::file::make_collector( keywords::target = "log" // where to store rotated files )); // Upon restart, scan the target directory for files matching the file_name pattern sink-&gt;locked_backend()-&gt;scan_for_files(); sink-&gt;locked_backend()-&gt;set_formatter( fmt::format("%1%: [%2%] [%3%] - %4%") % fmt::attr&lt; unsigned int &gt;("Line #") % fmt::date_time&lt; boost::posix_time::ptime &gt;("TimeStamp") % fmt::attr&lt; boost::thread::id &gt;("ThreadID") % fmt::message() ); // Add it to the core logging::core::get()-&gt;add_sink(sink); // Add some attributes too shared_ptr&lt; logging::attribute &gt; attr(new attrs::local_clock); logging::core::get()-&gt;add_global_attribute("TimeStamp", attr); attr.reset(new attrs::counter&lt; unsigned int &gt;); logging::core::get()-&gt;add_global_attribute("Line #", attr); // Create logging threads boost::barrier bar(THREAD_COUNT); boost::thread_group threads; for (unsigned int i = 0; i &lt; THREAD_COUNT; ++i) threads.create_thread(boost::bind(&amp;thread_fun, boost::ref(bar))); // Wait until all action ends threads.join_all(); return 0; } catch (std::exception&amp; e) { std::cout &lt;&lt; "FAILURE: " &lt;&lt; e.what() &lt;&lt; std::endl; return 1; } } </code></pre> <p>Source is compiled under Visual Studio 2008. boost.log compiled for boost 1.40.</p> <p>Any help is highly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload