[Boost] [Log] Problem with Release mode build

Hi, I have been using boost log with two of my projects, one an VC++ 2008 exe and another a VC++ DLL. Boost log was working as expected in the Debug mode. But when I compiled the projects in release mode, the boost log with the exe is not logging anything on the file and the dll is creating an access violation. Following is the call stack which is throwing the error. cnbc.dll!boost::log_mt_nt5::sources::basic_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex>
::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 269 + 0x15 bytes C++ cnbc.dll!boost::log_mt_nt5::sources::basic_severity_logger<boost::log_mt_nt5::sources::basic_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex> ,int>::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 226 + 0xc bytes C++ cnbc.dll!boost::log_mt_nt5::sources::basic_composite_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex>,boost::mpl::vector1<boost::log_mt_nt5::sources::severity<int>
::open_record<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 509 + 0x14 bytes C++
I have compiled the boost in release mode and as shared. Following is the command I used. , .\bjam.exe --with-log --with-filesystem --with-system --with-date_time --with-thread --with-regex define=BOOST_ALL_DYN_LINK variant=release link=shared stage What am i doing wrong here?? Thanks, Siva. .

Hi, On further investigation, I have narrowed down the issue to this line. sources::wseverity_logger_mt<> &lg = ::get_my_log(); <================ This line is not returning the lg object from Global Macro. BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(my_log, sources::wseverity_logger_mt<>) { Log_Init(); sources::wseverity_logger_mt<> lg; return lg; } This is not working properly only in release mode and working well in debug mode. Environment I am using is VC++ 2008. What am I missing?? Thanks, Siva. On Thu, Aug 26, 2010 at 6:02 PM, Sivaram Kannan <siva.devel@gmail.com> wrote:
Hi,
I have been using boost log with two of my projects, one an VC++ 2008 exe and another a VC++ DLL. Boost log was working as expected in the Debug mode. But when I compiled the projects in release mode, the boost log with the exe is not logging anything on the file and the dll is creating an access violation. Following is the call stack which is throwing the error.
cnbc.dll!boost::log_mt_nt5::sources::basic_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex>
::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 269 + 0x15 bytes C++ cnbc.dll!boost::log_mt_nt5::sources::basic_severity_logger<boost::log_mt_nt5::sources::basic_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex> ,int>::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 226 + 0xc bytes C++ cnbc.dll!boost::log_mt_nt5::sources::basic_composite_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex>,boost::mpl::vector1<boost::log_mt_nt5::sources::severity<int>
::open_record<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 509 + 0x14 bytes C++
I have compiled the boost in release mode and as shared. Following is the command I used. , .\bjam.exe --with-log --with-filesystem --with-system --with-date_time --with-thread --with-regex define=BOOST_ALL_DYN_LINK variant=release link=shared stage
What am i doing wrong here??
Thanks, Siva.
.

Single stepping I found the following line from the global macro sources::wseverity_logger_mt<> lg; <=================== is not creating the lg object at all. What is the problem in the release mode?? As a summary of the problem, * An exe build in debug/release mode is working properly. * This application is a dll. * The same dll is working properly in debug mode. Thanks, Siva. On Fri, Aug 27, 2010 at 11:03 AM, Sivaram Kannan <siva.devel@gmail.com> wrote:
Hi,
On further investigation, I have narrowed down the issue to this line.
sources::wseverity_logger_mt<> &lg = ::get_my_log(); <================
This line is not returning the lg object from Global Macro.
BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(my_log, sources::wseverity_logger_mt<>) { Log_Init(); sources::wseverity_logger_mt<> lg; return lg; }
This is not working properly only in release mode and working well in debug mode. Environment I am using is VC++ 2008. What am I missing??
Thanks, Siva.
On Thu, Aug 26, 2010 at 6:02 PM, Sivaram Kannan <siva.devel@gmail.com> wrote:
Hi,
I have been using boost log with two of my projects, one an VC++ 2008 exe and another a VC++ DLL. Boost log was working as expected in the Debug mode. But when I compiled the projects in release mode, the boost log with the exe is not logging anything on the file and the dll is creating an access violation. Following is the call stack which is throwing the error.
cnbc.dll!boost::log_mt_nt5::sources::basic_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex>
::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 269 + 0x15 bytes C++ cnbc.dll!boost::log_mt_nt5::sources::basic_severity_logger<boost::log_mt_nt5::sources::basic_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex> ,int>::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 226 + 0xc bytes C++ cnbc.dll!boost::log_mt_nt5::sources::basic_composite_logger<wchar_t,boost::log_mt_nt5::sources::wseverity_logger_mt<int>,boost::log_mt_nt5::sources::multi_thread_model<boost::shared_mutex>,boost::mpl::vector1<boost::log_mt_nt5::sources::severity<int>
::open_record<boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > >(const boost::parameter::aux::tagged_argument<boost::log_mt_nt5::keywords::tag::severity,enum severity const > & args={...}) Line 509 + 0x14 bytes C++
I have compiled the boost in release mode and as shared. Following is the command I used. , .\bjam.exe --with-log --with-filesystem --with-system --with-date_time --with-thread --with-regex define=BOOST_ALL_DYN_LINK variant=release link=shared stage
What am i doing wrong here??
Thanks, Siva.
.

On 27.08.2010 10:30, Sivaram Kannan wrote:
Single stepping I found the following line from the global macro
sources::wseverity_logger_mt<> lg;<===================
is not creating the lg object at all. What is the problem in the release mode?? As a summary of the problem,
* An exe build in debug/release mode is working properly. * This application is a dll. * The same dll is working properly in debug mode.
Sorry for the late response. Do I get it right that you built Boost.Log as dll? If so, please elaborate what you mean by "not creating the lg object at all". Does execution reach this line? If not, then what happens before it? I bet it is somehow related to the Log_Init function you call before it.

Hi,
Do I get it right that you built Boost.Log as dll?
I have a DLL application to which Boost.Log is linked with. I tried building the boost with both options linkage=static, linkage=shared.
If so, please elaborate what you mean by "not creating the lg object at all". Does execution reach this line? If not, then what happens before it?
Execution does reaches this line. But I could not see any instance getting created in the Locals tab. I repeat the point that this works well in the debug mode.
I bet it is somehow related to the Log_Init function you call before it.
I am not very sure. Here is the function. I am calling this function from the BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT. void Log_Init() { boost::function< void (std::wostream&, boost::log::wrecord const&) > formatter = boost::log::formatters::wstream << boost::log::formatters::date_time< boost::posix_time::ptime >(L"TimeStamp") << L" *" << boost::log::formatters::attr< int
(L"Severity") << L"* " << boost::log::formatters::wmessage();
boost::shared_ptr< sinks::synchronous_sink<boost::log::sinks::wtext_file_backend> > sink = boost::log::winit_log_to_file( keywords::file_name = L"C:\\logtst.log", // file name pattern keywords::rotation_size = 1 * 1024 * 1024, // rotate files every 1 MiB... keywords::open_mode = std::ios_base::app, keywords::severity = debug, keywords::auto_flush = true ); sink->locked_backend()->set_formatter(formatter); // Register common attributes boost::log_mt_nt5::wadd_common_attributes(); } What am I missing here? Thanks, siva.

On 08/31/2010 08:30 AM, Sivaram Kannan wrote:
Hi,
Do I get it right that you built Boost.Log as dll?
I have a DLL application to which Boost.Log is linked with. I tried building the boost with both options linkage=static, linkage=shared.
Ok, if you use dlls you should build Boost.Log as a shared library, too.
If so, please elaborate what you mean by "not creating the lg object at all". Does execution reach this line? If not, then what happens before it?
Execution does reaches this line. But I could not see any instance getting created in the Locals tab. I repeat the point that this works well in the debug mode.
You mean the Locals tab in the IDE? In release builds (i.e. when optimization is on) the debugger is often unable to correctly show variables. In your case the logger variable is probably optimized away due to NRVO. If it reaches the logger construction, I'm rather positive that it's not the problem.
I bet it is somehow related to the Log_Init function you call before it.
I am not very sure. Here is the function. I am calling this function from the BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT.
[snip]
What am I missing here?
Nothing criminal here too. Could you show your logging expression where the crash occurs? I'll try to reproduce the problem locally, but it would be very helpful if you could create a small code sample that crashes.
participants (2)
-
Andrey Semashev
-
Sivaram Kannan