|
Boost : |
Subject: Re: [boost] [log] auto_flush not flushing?
From: Michael Caisse (boost_at_[hidden])
Date: 2010-06-13 16:08:55
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk