
Hi Andrey, 2012/1/23 Andrey Semashev <andrey.semashev@gmail.com>
Hi,
[My apologies for the long post]
I'm trying to port filters and formatters of Boost.Log to Boost.Phoenix
That's exciting :-) [...] What I'm trying to achieve is something along these lines (this is not a
finalized interface yet):
enum my_severity { info, warning, error };
BOOST_LOG_REGISTER_ATTRIBUTE("Severity", severity, my_severity)
filter flt = severity >= warning; formatter fmt = stream << "[" << severity << "] " << message;
Here, "stream" and "message" are keywords provided by Boost.Log, the former is a placeholder for the stream argument of the formatter function, and the latter returns the result of the record::message() method.
Now, the BOOST_LOG_REGISTER_ATTRIBUTE macro is what I'm struggling on. It should create a new keyword (severity) which should:
1. Be a POD object to be statically initialized. 2. Contain the information on the type (my_severity) and name ("Severity") of the attribute to be able to extract it from the log record. 3. Be a Phoenix object to initiate lazy expression generation.
I wrote the sample code that conforms these requirements, full code attached.
From what I gathered from the docs and examples, the generated keyword should be a terminal, in terms of Proto. Am I correct?
I think it's a phoenix actor which is also a proto terminal. In order to produce the value,
during the evaluation the keyword should receive either a log record or a attribute_values_view and I can't quite understand how do I do that. Basically, I don't quite understand how do I declare and implement a terminal so that it works with Phoenix. This question also applies to the "stream" and "message" keywords but I suspect the solution will be similar.
Maybe there is an example of doing this in the docs or elsewhere. I'll be glad if someone provides a link or example of doing this. Thanks in advance.
HTH