Inability to print LINE, FILE, FUNCTION in Boost.Log?
I find the simplest things the most frustrating to accomplish in Boost.Log. I know that some compilers have predefined preprocessor macros to provide information. MSVC for example has __LINE__, __FILE__, etc. I need Boost.Log to print line, file, and function information for me in a platform agnostic way. The documentation is not easy to navigate through and find the information I need. Also examples on this are sparse. I've seen some people calling BOOST_LOG_NAMED_SCOPE manually prior to each log statement. This seems unintuitive. How can I simply print this contextual information with each log line in an automated way? Can't Boost.Log piggy-back on compiler features available to it?
On 05.08.2015 16:30, Robert Dailey wrote:
I find the simplest things the most frustrating to accomplish in Boost.Log. I know that some compilers have predefined preprocessor macros to provide information. MSVC for example has __LINE__, __FILE__, etc.
I need Boost.Log to print line, file, and function information for me in a platform agnostic way. The documentation is not easy to navigate through and find the information I need. Also examples on this are sparse. I've seen some people calling BOOST_LOG_NAMED_SCOPE manually prior to each log statement. This seems unintuitive.
How can I simply print this contextual information with each log line in an automated way? Can't Boost.Log piggy-back on compiler features available to it?
__LINE__ and __FILE__ are pretty much standard thing, not MSVC specific ...
As for the documentation, it is not so bad, it is just written like a
cookbook that requires a master chef degree to be able to follow the
recipes... :-) and is in some places a bit behind the actual
implementation. It took me couple of days of experimenting with the
library to get me where I wanted to be ...
There are several ways to achieve what you're after ... the path I've is
to add your own attributes to each log record (which you now can do even
after the record was opened and went through filters), and to define
sink formatters that will display them. In my final solution I have
replaced boost boilerplate log macros with my own which add required
attributes. For instance, using the severity channel logger:
typedef boost::log::sources::severity_channel_logger
participants (2)
-
Leon Mlakar
-
Robert Dailey