Boost logo

Boost Users :

Subject: Re: [Boost-users] Include line number in boost logs
From: Leon Mlakar (leon_at_[hidden])
Date: 2015-08-26 06:15:53


On 26.08.2015 09:51, Florian Lindner wrote:
> Leon Mlakar wrote:
>
>> On 25.08.2015 11:15, Florian Lindner wrote:
>>> I finally got it. Shared the answer on stack overflow:
>>>
>>> http://stackoverflow.com/a/32200033/3585934
>>>
>>>
>>>
>> Thank you for sharing this. I'd just recommend to write macro #define's
>> in such a way that they are syntactically and semantically neutral ...
>> using do { .... macro contents ... } while (false) is a good way to
>> achieve this. For instance, this:
>>
>> #define logInfo(methodname, message) do { \
>> LOG_LOCATION; \
>> BOOST_LOG_SEV(_log, boost::log::trivial::severity_level::trace) <<
>> message \
>> while (false)
>>
>> would allow constructs such as:
>>
>> if (something)
>> logInfo("my_func", "my message");
>>
>> which not only would not fail with compilation errors but would behave
>> really strange with your original code.
> Ah, thanks, that sounds wise. Isn't is sufficient to just use curly braces
> {...} instead of do{..} while (false)?
Curly braces (syntactically a block) would cause compilation error in:

     if (something)
         logInfo("my_func", "my message);
     else
         whatever;

due to an extra empty statement between if and else.

Cheers,

Leon


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net