
14 Nov
2013
14 Nov
'13
1:25 p.m.
I found the answer for the previous problem. When named_scope is used, the BOOST_LOG_NAMED_SCOPED() must be used in every scope we want to register. This macro fills the values of the named_scoped variables in order to be available for the logger and the formatter. El jueves, 7 de noviembre de 2013 09:10:56 UTC+1, Víctor Yo escribió: > > As I said, I discovered that I was using incorrect names in the formatter. > I though that I had to use the same attribute names there but it happens > that I had to use the names associated to the formatter. I post the new > code for better understanding: > > frontend -> set_formatter > ( > boost::log::expressions::stream > <<_lineID > <<" ["<<boost::log::expressions::format_named_scope(_scope, > boost::log::keywords::format = "%n (%f:%l)") > <<"] "<< boost::log::expressions::format_date_time< > boost::posix_time::ptime >("TimeStamp", "%H:%M:%S") > <<" <"<<boost::log::expressions::attr< severity_level >("Severity") > <<"> "<<boost::log::expressions::message > ); > > In my firts code I used attributes names but it is customary to use > expressions names corresponding to the variables we want to use in the log. > However, I'm still having problems with the named_scope because it is not > working. I have nothing printed in the log messages when it is supposed to > print the scope, the file name and the line number. Anyone could help me > with that? Thank you very much. > > El miércoles, 6 de noviembre de 2013 08:36:03 UTC+1, Víctor Yo escribió: >> >> Thank you Johan. I have read that documentation before. Anyway, I >> discovered that one of the problems I had is that I need to use formatters >> types asociated with the variables (or objects) I want to use in the log, >> but I was using the variable types instead. I'm working on it and when I >> have everything working, I will post the changes here for future reference. >> I think I have it under control :D Thank you! >> >> El martes, 5 de noviembre de 2013 22:19:58 UTC+1, Johan Lundberg escribió: >>> >>> Hi, >>> >>> In the tutorial here: >>> >>> http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/tutorial/formatters.html >>> >>> There is a link to this example: >>> >>> http://www.boost.org/doc/libs/1_54_0/libs/log/example/doc/tutorial_fmt_format.cpp >>> >>> Which I can compile fine like this: >>> g++ -DBOOST_ALL_DYN_LINK -Lboost-trunk155beta_inst/lib/ -lboost_system >>> -lboost_log -lboost_filesystem -lboost_thread -I >>> boost-trunk155beta_inst/include/ boost_log_format.cpp >>> >>> Could start from that? >>> >>> cheers, Johan >>> >>> >>> 2013/11/5 Víctor Yo <rcpo...@gmail.com> >>> >>>> 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 mailing list >>>> Boost...@lists.boost.org >>>> http://lists.boost.org/mailman/listinfo.cgi/boost-users >>>> >>> >>>