Boost.Log: Set formatter for named_scope attr.

Hi, Being new to Boost.Log (and Boost in general) I have spent the last few days trying to implement Boost.Log - which Is working fairly well by now. However - I encountered one problem that I've not been able to solve by now, although it seems to me quite trivial: I have successfully registered the "named_scope" attribute and I am populating its value by a call to BOOST_LOG_FUNCTION. This works well and I can see the function-name in my log-output. However - I also want the line-number and the file-name, and discovered that there's a possibility to set the output-format of the "named_scope" attribute (which already incorporates file-name and line-number info) like so: #include <boost/log/expressions/formatters/named_scope.hpp> sink->set_formatter(expr::stream << expr::format_named_scope("Scopes", "%n")); As documented here: http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/detailed/expressi... I just don't seem to find any way to get to my sink - which is configured in a settings-file and evaluated by a call to the init_from_stream() function. Is there any way to query for all the sinks - or get a sink by name? How is one supposed to set a sink formatter for a sink which was generated by the library and not the user? Or is there a way to specify the output-format for named attributes via a settings-file as well? As far as I can see it's only possible to format the output of a log record as a whole - but not single attributes. Also: Is it correct, that the above function will only set the format for the "Scopes" attribute - which means I could call this function repeatedly for lets say the "TimeStamp" attribute as well? Best regards, David

I have some doubts about your question: are you using the named_acope attribute yet? If that is the case, just needs to include some other tags like the next example <<boost::log::expressions::format_named_scope(_scope,
boost::log::keywords::format = "%n (%f : %l)")
This line would print something like: "void main() (main.cpp : 25)" If that is not the case, please, could you be more specific about how did you set your logger? I have been struggling the past weeks with that and I may help you. Best regards! El lunes, 30 de septiembre de 2013 14:01:29 UTC+2, David Puffer escribió:
Hi,
Being new to Boost.Log (and Boost in general) I have spent the last few days trying to implement Boost.Log - which Is working fairly well by now. However - I encountered one problem that I've not been able to solve by now, although it seems to me quite trivial:
I have successfully registered the "named_scope" attribute and I am populating its value by a call to BOOST_LOG_FUNCTION. This works well and I can see the function-name in my log-output. However - I also want the line-number and the file-name, and discovered that there's a possibility to set the output-format of the "named_scope" attribute (which already incorporates file-name and line-number info) like so:
#include <boost/log/expressions/formatters/named_scope.hpp>
sink->set_formatter(expr::stream << expr::format_named_scope("Scopes", "%n"));
As documented here:
http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/detailed/expressi...
I just don't seem to find any way to get to my sink - which is configured in a settings-file and evaluated by a call to the init_from_stream()function.
Is there any way to query for all the sinks - or get a sink by name? How is one supposed to set a sink formatter for a sink which was generated by the library and not the user? Or is there a way to specify the output-format for named attributes via a settings-file as well? As far as I can see it's only possible to format the output of a log record as a whole - but not single attributes.
Also: Is it correct, that the above function will only set the format for the "Scopes" attribute - which means I could call this function repeatedly for lets say the "TimeStamp" attribute as well?
Best regards,
David

I'm sorry. I saw that I used my own keywords and that maybe confusing. The line should be (in your example) like this: <<boost::log::expressions::format_named_scope("Scopes", boost::log::keywords::format = "%n (%f : %l)") and about the part "boost::log::keywords::format =" try with your form (if it works for the moment). Let me know if finally worked. El lunes, 30 de septiembre de 2013 14:01:29 UTC+2, David Puffer escribió:
Hi,
Being new to Boost.Log (and Boost in general) I have spent the last few days trying to implement Boost.Log - which Is working fairly well by now. However - I encountered one problem that I've not been able to solve by now, although it seems to me quite trivial:
I have successfully registered the "named_scope" attribute and I am populating its value by a call to BOOST_LOG_FUNCTION. This works well and I can see the function-name in my log-output. However - I also want the line-number and the file-name, and discovered that there's a possibility to set the output-format of the "named_scope" attribute (which already incorporates file-name and line-number info) like so:
#include <boost/log/expressions/formatters/named_scope.hpp>
sink->set_formatter(expr::stream << expr::format_named_scope("Scopes", "%n"));
As documented here:
http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/detailed/expressi...
I just don't seem to find any way to get to my sink - which is configured in a settings-file and evaluated by a call to the init_from_stream()function.
Is there any way to query for all the sinks - or get a sink by name? How is one supposed to set a sink formatter for a sink which was generated by the library and not the user? Or is there a way to specify the output-format for named attributes via a settings-file as well? As far as I can see it's only possible to format the output of a log record as a whole - but not single attributes.
Also: Is it correct, that the above function will only set the format for the "Scopes" attribute - which means I could call this function repeatedly for lets say the "TimeStamp" attribute as well?
Best regards,
David
participants (2)
-
David Puffer
-
Víctor Yo