[log] auto_flush not flushing?

I'm running on Vista and compiled with VC8. I have initialized the backend like this: ----------------------- typedef sinks::synchronous_sink< sinks::text_file_backend > sink_type; boost::shared_ptr< sink_type > sink = boost::make_shared< sink_type >( keywords::file_name = "%Y%m%d_%H%M%S_%5N.log", keywords::open_mode = (std::ios::out | std::ios::app), keywords::auto_flush = true, keywords::rotation_size = rotate_size // rotation size, in characters ); if( target_directory.empty() ) { target_directory = suggest_target_directory(); } // Set up where the rotated files will be stored sink->locked_backend()->set_file_collector( sinks::file::make_collector( keywords::target = target_directory, // where to store rotated files keywords::max_size = max_stored_size, // maximum total size of the stored files, in bytes keywords::min_free_space = min_free_space // minimum free space on the drive, in bytes )); sink->locked_backend()->auto_flush(true); // Upon restart, scan the target directory for files matching the file_name pattern sink->locked_backend()->scan_for_files(); typedef aux::add_common_attributes_constants< char > traits_t; sink->locked_backend()->set_formatter( formatters::stream << formatters::attr< unsigned int
(traits_t::line_id_attr_name()) << " [" << formatters::date_time< boost::posix_time::ptime (traits_t::time_stamp_attr_name()) << "] [" << formatters::attr< attributes::current_thread_id::held_type >(traits_t::thread_id_attr_name()) << "] [" << formatters::attr< severity_level (sources::aux::severity_attribute_name< char >::get()) << "] " << formatters::message< char >() );
core::get()->add_sink(sink); --------- Notice I have also added a call to auto_flush (for good measure with the keyword didn't work (o; ) What happens is that the log file shows up after the program exits. Since I was hoping to tail the file for some debug ... that isn't very convenient. Ideas of what I have done wrong? TIA michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

On 06/12/2010 07:32 AM, Michael Caisse wrote:
What happens is that the log file shows up after the program exits. Since I was hoping to tail the file for some debug ... that isn't very convenient.
Ideas of what I have done wrong?
The file is only created when the first log record is written to it. Could it be the case that you don't log until the end of the application run time or filters reject records? Also, is it possible that the execution time is very short to tell for sure when the record is written to the file? The auto-flush feature is quite straightforward, I can't see from the code how it could do wrong.

Andrey Semashev wrote:
On 06/12/2010 07:32 AM, Michael Caisse wrote:
What happens is that the log file shows up after the program exits. Since I was hoping to tail the file for some debug ... that isn't very convenient.
Ideas of what I have done wrong?
The file is only created when the first log record is written to it. Could it be the case that you don't log until the end of the application run time or filters reject records? Also, is it possible that the execution time is very short to tell for sure when the record is written to the file?
The auto-flush feature is quite straightforward, I can't see from the code how it could do wrong.
The program is terminated when I "enter a key" and several items have been sent long before. I'll see if I can come up with a small and self-contained example. Thanks - michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

Andrey Semashev wrote:
On 06/12/2010 07:32 AM, Michael Caisse wrote:
What happens is that the log file shows up after the program exits. Since I was hoping to tail the file for some debug ... that isn't very convenient.
Ideas of what I have done wrong?
The file is only created when the first log record is written to it. Could it be the case that you don't log until the end of the application run time or filters reject records? Also, is it possible that the execution time is very short to tell for sure when the record is written to the file?
The auto-flush feature is quite straightforward, I can't see from the code how it could do wrong.
Hi Andrey - The following is a reduced example that still fails. The file is not created until the program is exiting. Thank you for the help. ------------------------- #include <fstream> #include <iostream> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <boost/filesystem/convenience.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/log/sources/severity_logger.hpp> #include <boost/log/sources/record_ostream.hpp> #include <boost/log/sources/global_logger_storage.hpp> #include <boost/log/keywords/severity.hpp> #include <boost/log/formatters/stream.hpp> #include <boost/log/formatters/message.hpp> #include <boost/log/sinks/text_file_backend.hpp> #include <boost/log/sinks/sync_frontend.hpp> #include <boost/log/utility/init/common_attributes.hpp> namespace omd{ namespace log{ enum severity_level{ trace, info, }; typedef boost::log::sources::severity_logger_mt< severity_level > omd_logger; namespace detail{ void init() { using namespace boost::log; boost::log::add_common_attributes<char>(); typedef sinks::synchronous_sink<sinks::text_file_backend> sink_type; boost::shared_ptr<sink_type> sink = boost::make_shared<sink_type>( keywords::file_name = "%Y%m%d_%H%M%S_%5N.log", keywords::open_mode = (std::ios::out | std::ios::app), keywords::auto_flush = true, keywords::rotation_size = 16*1024 ); sink->locked_backend()->set_file_collector( sinks::file::make_collector( keywords::target = "logs", keywords::max_size = 16*1024*1024, keywords::min_free_space = 100*1024*1024 )); sink->locked_backend()->scan_for_files(); typedef aux::add_common_attributes_constants< char > traits_t; sink->locked_backend()->set_formatter( formatters::stream << formatters::message<char>() ); core::get()->add_sink(sink); } } BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(logger, omd_logger) { omd::log::detail::init(); return omd_logger(::boost::log::keywords::severity = info); } #define OMD_LOG(level)\ BOOST_LOG_STREAM_WITH_PARAMS(::omd::log::get_logger(),\ (::boost::log::keywords::severity = ::omd::log::level)) }} int main() { OMD_LOG(info) << "starting..."; char tmp; std::cin >> tmp; OMD_LOG(info) << "leaving."; return 0; } ------------------------------------------ -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

On 06/14/2010 12:08 AM, Michael Caisse wrote:
Andrey Semashev wrote:
On 06/12/2010 07:32 AM, Michael Caisse wrote:
What happens is that the log file shows up after the program exits. Since I was hoping to tail the file for some debug ... that isn't very convenient.
Ideas of what I have done wrong?
The file is only created when the first log record is written to it. Could it be the case that you don't log until the end of the application run time or filters reject records? Also, is it possible that the execution time is very short to tell for sure when the record is written to the file?
The auto-flush feature is quite straightforward, I can't see from the code how it could do wrong.
Hi Andrey -
The following is a reduced example that still fails. The file is not created until the program is exiting.
Thank you for the help.
It works as expected on my Ubuntu 9.10 ("starting..." is in the file when waiting for input). I tried on trunk, but the related code from v1 is still the same. What library version do you use?

Andrey Semashev wrote:
On 06/14/2010 12:08 AM, Michael Caisse wrote:
Hi Andrey -
The following is a reduced example that still fails. The file is not created until the program is exiting.
Thank you for the help.
It works as expected on my Ubuntu 9.10 ("starting..." is in the file when waiting for input). I tried on trunk, but the related code from v1 is still the same. What library version do you use?
I suspect the important part was mentioned in my first email. I am experiencing the problem in windows, VC8 and the library was a release from sourceforge. What do you mean by "trunk"? It isn't in the boost trunk so should I assume sourceforge? How can I determine a "version" for the library given some source code? michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

On 15.06.2010 8:05, Michael Caisse wrote:
Andrey Semashev wrote:
On 06/14/2010 12:08 AM, Michael Caisse wrote:
Hi Andrey -
The following is a reduced example that still fails. The file is not created until the program is exiting.
Thank you for the help.
It works as expected on my Ubuntu 9.10 ("starting..." is in the file when waiting for input). I tried on trunk, but the related code from v1 is still the same. What library version do you use?
I suspect the important part was mentioned in my first email. I am experiencing the problem in windows, VC8 and the library was a release from sourceforge.
I can't test with vc8 as I don't have it, but with vc9 it works as expected, too. Tested release 1.0 this time, Windows 7.
What do you mean by "trunk"? It isn't in the boost trunk so should I assume sourceforge?
Yes, the library is currently hosted on SourceForge.
How can I determine a "version" for the library given some source code?
If you downloaded it as a released archive, it is sufficient to say the version of the release. If you checked it out from SVN then state the revision.

On 15.06.2010 8:05, Michael Caisse wrote:
Andrey Semashev wrote:
On 06/14/2010 12:08 AM, Michael Caisse wrote:
Hi Andrey -
The following is a reduced example that still fails. The file is not created until the program is exiting.
Thank you for the help.
It works as expected on my Ubuntu 9.10 ("starting..." is in the file when waiting for input). I tried on trunk, but the related code from v1 is still the same. What library version do you use?
I suspect the important part was mentioned in my first email. I am experiencing the problem in windows, VC8 and the library was a release from sourceforge.
It just occurred to me. Is it possible that you're looking at a wrong folder? The file appears in the current directory of your application.

Andrey Semashev wrote:
On 15.06.2010 8:05, Michael Caisse wrote:
Andrey Semashev wrote:
On 06/14/2010 12:08 AM, Michael Caisse wrote:
Hi Andrey -
The following is a reduced example that still fails. The file is not created until the program is exiting.
Thank you for the help.
It works as expected on my Ubuntu 9.10 ("starting..." is in the file when waiting for input). I tried on trunk, but the related code from v1 is still the same. What library version do you use?
I suspect the important part was mentioned in my first email. I am experiencing the problem in windows, VC8 and the library was a release from sourceforge.
It just occurred to me. Is it possible that you're looking at a wrong folder? The file appears in the current directory of your application.
The file does show up after a character is entered and the program exists. I'll give it a try on linux today and see that I can verify it works and then try to proceed from there. Thank you for your responses. michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

On 06/15/2010 11:32 PM, Michael Caisse wrote:
The file does show up after a character is entered and the program exists. I'll give it a try on linux today and see that I can verify it works and then try to proceed from there.
You could walk through the code in the debugger. In particular, see if the file is actually created when flush() is called in basic_text_file_backend::do_consume. And whether it is actually called, for that matter. I have no idea why it doesn't work in your case.
participants (2)
-
Andrey Semashev
-
Michael Caisse