Boost logo

Boost Users :

Subject: [Boost-users] [Log] Error with operator<< in basic_formatting_ostream
From: Víctor Yo (rcpoetics_at_[hidden])
Date: 2013-11-05 03:13:28


Hi ewveryone,

I'm working lately with Boost.Log (I'm a newbie) library and I want to
write a logger with some parameters and formatting options. I followed the
documentation, I created a backend and a frontend and I tried to format the
output in the frontend with the set_formatter() function. I tried with the
Lambda style and with the Boost.Format style but I'm getting an error that
I can not locate. Iwas working on it for the last two whole days but I
couldn't find a solution. It is related with the basic_formatting_ostream,
but I don't understand what that means. I defined the backend and attached
to it two streams (to a file and to cout)

       typedef boost::log::sinks::text_ostream_backend our_backend;
       typedef boost::log::sinks::synchronous_sink<our_backend>
our_frontend;

//............................................................................................................................................

       boost::shared_ptr<our_backend> backend =
boost::make_shared<our_backend>();
       //Stream definitions
       boost::shared_ptr<std::ostream> stream_out(&std::cout,
boost::log::empty_deleter());
       boost::shared_ptr<std::ostream> stream_file(new
std::ofstream("file_logger.log"));
       backend -> add_stream(stream_out);
       backend -> add_stream(stream_file);

Created the frontend (and wrapping the backend to it)

       //Wrap the backend into the frontend and register in the core.
       //The frontend provides synchronization for the backend.
       boost::shared_ptr<our_frontend> frontend(new our_frontend(backend));

And now come the offending code which is supposed to format the output
(note that the first commented block was my first try). None of them works
and the error is the same in both cases:

*/*frontend -> set_formatter*
* (*
* boost::log::expressions::format("[%1%] %2%, File: %3%, Line:
%4% <%5%>: %6% ")*
* % boost::log::attributes::counter< unsigned int >(1)*
* % boost::log::attributes::local_clock()*
* % boost::log::expressions::attr< severity_level
>("Severity")*
* % boost::log::expressions::message*
* );*/*

       //We are going to define the formatter in a different style to try
to get formatted output
       frontend -> set_formatter
       (
  boost::log::expressions::stream
   << boost::log::attributes::counter< unsigned int >(1)
  <<" ["<< boost::log::attributes::local_clock()
  <<"] <"<< boost::log::expressions::attr< severity_level >("Severity")
  <<"> "<< boost::log::expressions::message
   );

The error I get is the next one:

*/home/victor/Programacion/workspace/opice/build-parallel/../libs/include/boost/log/utility/formatting_ostream.hpp:664:5:
error: no match for ‘operator<<’ in ‘(&
strm)->boost::log::v2_mt_posix::basic_formatting_ostream<CharT, TraitsT,
AllocatorT>::stream [with CharT = char, TraitsT = std::char_traits<char>,
AllocatorT = std::allocator<char>,
boost::log::v2_mt_posix::basic_formatting_ostream<CharT, TraitsT,
AllocatorT>::ostream_type = std::basic_ostream<char>]() << value’*

And I really don't know what is happening. I also included a lot of files
(I'm sure I included too much files, indeed) to be sure it was not caused
by some undefined operator or something similar. However I still have the
same problem. The includes are:

#include <iostream>
#include <fstream>
#include <string>

#include <boost/thread/shared_mutex.hpp>

#include <boost/log/core.hpp>
#include <boost/log/common.hpp>
#include <boost/make_shared.hpp>
#include <boost/log/expressions.hpp>

#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/console.hpp> //puede ser innecesario
#include <boost/log/utility/setup/common_attributes.hpp> //puede ser
innecesario
#include <boost/log/utility/empty_deleter.hpp>

#include<boost/thread/mutex.hpp>
#include <boost/log/attributes/timer.hpp>
#include <boost/log/attributes/mutable_constant.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/utility/formatting_ostream.hpp>

#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sinks/sync_frontend.hpp>

#include <boost/log/support/date_time.hpp>

As you can see, they are probably redundant or innecessary but I could rip
off that files when I could get the program compiled. Now, I'm out of ideas
so any help you could bring me should be very appreciated. Thank you in
advance.

Victor Hevia



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net