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-17 12:17:51


#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 vgrinenko@…):

 Hi,
 it has nothing with MFC, sorry. Just this code is enough.

 Visual Studio 2015.

 For example:
 {{{
 Detected memory leaks!
 Dumping objects ->
 {887} normal block at 0x00B6A0F8, 128 bytes long.
  Data: < TimeStamp: 2017> 00 54 69 6D 65 53 74 61 6D 70 3A 20 32 30 31 37
 ...
 }}}

 {{{
 // ConsoleApplication_wo_MFC.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

 #include <stdio.h>
 #include <tchar.h>
 #include <windows.h>
 #include <ppltasks.h>
 #include <thread>

 #define _CRTDBG_MAP_ALLOC
 #include <stdlib.h>
 #include <crtdbg.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>
 #include <boost/locale/localization_backend.hpp>

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

 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;
         _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

         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();
         return nRetCode;
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/12867#comment:4>
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-17 12:24:24 UTC