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
application.
//
#define _CRT_SECURE_NO_WARNINGS
#define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_LIB_DIAGNOSTIC
#define CGAL_LIB_DIAGNOSTIC
// From StdAfx.h ->
#include <SDKDDKVer.h>
#include <stdio.h>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString
constructors will be explicit
#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS // remove support for MFC
controls in dialogs
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows
headers
#endif
#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4
Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common
Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#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
#endif
// 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
failed\n");
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
typedef
sinks::synchronous_sink<sinks::text_file_backend> file_sink;
src::severity_channel_logger_mt<boost::log::trivial::severity_level>
logger(keywords::channel = "L");
boost::shared_ptr<file_sink> sinkT(new
file_sink(keywords::file_name = "logs\\TestLogger_%6N.log"));
sinkT->set_formatter
(
expr::stream
<< " TimeStamp: " <<
expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d
%H:%M:%S")
<< " ThreadID: " <<
expr::attr<logging::thread_id>("ThreadID")
<< " Message: " << expr::smessage
);
logging::core::get()->add_sink(sinkT);
sinkT->set_filter(a_channel == "L");
logging::add_common_attributes();
BOOST_LOG(logger) << L"A message from the MAIN
thread";
std::thread testTthread([&]()
{
BOOST_LOG(logger) << L"A message from the
std::thread";
});
testTthread.join();
auto task = concurrency::create_task([&]()
{
// Produces memory leaks
BOOST_LOG(logger) << L"A message from the
concurrency::create_task thread";
});
task.wait();
BOOST_LOG(logger) << L"Is concurrency::create_task
done: " << task.is_done();
}
}
else
{
// TODO: change error code to suit your needs
wprintf(L"Fatal Error: GetModuleHandle failed\n");
nRetCode = 1;
}
return nRetCode;
}
}}}
-- Ticket URL: <https://svn.boost.org/trac10/boost/ticket/12867#comment:3> Boost C++ Libraries <http://www.boost.org/> 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