Re: [Boost-bugs] [Boost C++ Libraries] #12867: log library extensions

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12867: log library extensions
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-11-16 12:17:01

#12867: log library extensions
  Reporter: vgrinenko@… | Owner: Andrey Semashev
      Type: Feature Requests | Status: new
 Milestone: To Be Determined | Component: log
   Version: Boost 1.57.0 | Severity: Optimization
Resolution: | Keywords:

Comment (by anonymous):

 Hi Andrey,

 I have a problem with MFC applications, both shared and static.
 If logger is called from the std::thread there are no problems, but if
 from the concurrency::create_task - there are lot of memory leaks.
 Probably they are "fake" leaks, it happens if shared MFC unloaded too
 early, but the problem exist with a static MFC as well.
 Do you have any ideas?

 To reproduce the problem create an empty console application project with
 MFC, add code below and set paths to boost include and libs.

 Best regards, Victor.

 // ConsoleApplicationMFC.cpp : Defines the entry point for the console


 // From StdAfx.h ->
 #include <SDKDDKVer.h>

 #include <stdio.h>
 #include <tchar.h>
 constructors will be explicit
 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS // remove support for MFC
 controls in dialogs

 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows

 #include <afx.h>
 #include <afxwin.h> // MFC core and standard components
 #include <afxext.h> // MFC extensions
 #include <afxdtctl.h> // MFC support for Internet Explorer 4
 Common Controls
 #include <afxcmn.h> // MFC support for Windows Common

 #include <iostream>

 // <- From StdAfx.h

 #include <boost/log/core.hpp>
 #include <boost/log/expressions.hpp>
 #include <boost/log/attributes.hpp>
 #include <boost/log/utility/setup/common_attributes.hpp>
 #include <boost/log/sources/severity_channel_logger.hpp>
 #include <boost/log/trivial.hpp>
 #include <boost/log/support/date_time.hpp>
 #include <boost/log/utility/setup/console.hpp>
 #include <boost\log\sinks\text_file_backend.hpp>

 #if !defined(BOOST_LOG_NO_THREADS)
 #include <boost/thread/locks.hpp>
 #include <boost/thread/mutex.hpp>
 #endif // !defined(BOOST_LOG_NO_THREADS)
 #include <ppltasks.h>
 #include <thread>

 #ifdef _DEBUG
 #define new DEBUG_NEW

 // The one and only application object

 CWinApp theApp;

 using namespace std;
 namespace logging = boost::log;
 namespace src = boost::log::sources;
 namespace sinks = boost::log::sinks;
 namespace keywords = boost::log::keywords;
 namespace expr = boost::log::expressions;

 BOOST_LOG_ATTRIBUTE_KEYWORD(a_channel, "Channel", std::string)

 int main()
         int nRetCode = 0;

         HMODULE hModule = ::GetModuleHandle(nullptr);

         if (hModule != nullptr)
                 // initialize MFC and print and error on failure
                 if (!AfxWinInit(hModule, nullptr, ::GetCommandLine(), 0))
                         // TODO: change error code to suit your needs
                         wprintf(L"Fatal Error: MFC initialization
                         nRetCode = 1;
                         // TODO: code your application's behavior here.

 sinks::synchronous_sink<sinks::text_file_backend> file_sink;

 logger(keywords::channel = "L");
                         boost::shared_ptr<file_sink> sinkT(new
 file_sink(keywords::file_name = "logs\\TestLogger_%6N.log"));
                                 << " TimeStamp: " <<
 expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d
                                 << " ThreadID: " <<
                                 << " Message: " << expr::smessage
                         sinkT->set_filter(a_channel == "L");

                         BOOST_LOG(logger) << L"A message from the MAIN

                         std::thread testTthread([&]()
                                 BOOST_LOG(logger) << L"A message from the

                         auto task = concurrency::create_task([&]()
                                 // Produces memory leaks
                                 BOOST_LOG(logger) << L"A message from the
 concurrency::create_task thread";

                         BOOST_LOG(logger) << L"Is concurrency::create_task
 done: " << task.is_done();
                 // TODO: change error code to suit your needs
                 wprintf(L"Fatal Error: GetModuleHandle failed\n");
                 nRetCode = 1;

         return nRetCode;


Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-11-16 12:23:36 UTC