2

I asked this question on boost-users mailing list but unfortunately never got a response. Hopefully I'll have better luck here.

I'm trying to specify a format textually (eg, keywords::format = "blahblah", instead of using a compiled expression).

The idea is that the format can be reconfigured easily either through a command line parameter or through the configuration file without needing to recompile. However, it seems that anything specifying %Severity% when using a custom severity_level enum will simply not be output at all.

Take the example from boost_1_55_0/libs/log/example/keywords/main.cpp

Simply changing line 86 to be:

logging::add_console_log(std::clog, keywords::format = "%Severity% %TimeStamp%: %_%");

will exhibit the problem I believe I am trying to resolve.

My suspicion is that the core doesn't know about the custom Severity attribute because it hasn't been registered and so is unable to parse %Severity% to any formatter. In contrast, the add_file_log below that does correctly output the severity level because it uses a compiled expression and is therefore able to deduce what needs to be done (am I correct in that assumption)?

I seem to be unable to add an attribute to resolve this without rolling my own attribute class. How do I add an attribute or formatter related to the Severity which was declared with BOOST_LOG_ATTRIBUTE_KEYWORD? I think it's worth noting that if I remove the template parameter to severity_logger on line 123 so that it matches thus:

src::severity_logger< > slg; 

It then devolves into a standard int instead of an enum and the output is "correctly" seen -- as an int and not as a human-readable string. While this is okay for now, I would of course want it to be human-readable if possible. This is as it is in the example in boost_1_55_0/libs/log/example/settings_file/main.cpp.

inetknght
  • 4,300
  • 1
  • 26
  • 52
  • 1
    Matt Yang's answer [here](http://stackoverflow.com/a/24221423/2417774) seems to solve your problem. [Example](http://coliru.stacked-crooked.com/a/70716822add05c02). – llonesmiz Jun 21 '14 at 16:00
  • 1
    Took a little bit to remember that operator<< has to be declared in the same namespace as its types. After that, it worked. Thanks! – inetknght Jul 28 '14 at 20:44

0 Answers0